Sie sind auf Seite 1von 25

Chronoforms

Create a form to insert, save


and update data in the MySql
database
Record creation is limited to 1
per User

1. Create a new form

1. Go to the Chronoforms Forms


Manager
2. Create a new form
In this example I have created a form
with 2 multiple Checkbox Groups.
You can add any kinds of fields, just
adapt the code you will find below in
DB Read and DB Save Actions.

1. Create a new form


General tab

Add your titel

2. Design your form


Designer tab
Create your fields

2. Design your form

Designer tab
Create an UserID Hidden Field

2. Design your form

Designer tab : Create an Checkbox Group


General tab : Fill-in the fields accordingly

2. Design your form

Designer tab : Create an Checkbox Group


General tab : Fill-in the fields accordingly

2. Design your form

Designer tab : Create an Checkbox Group


Validation tab : change value if needed

2. Design your form

Designer tab : Create an Checkbox Group


Dynamic Data tab : do not change the value

2. Design your form

Designer tab : Create an Checkbox Group


Events data tab : add events if needed

2. Design your form

Designer tab
When you have finished with creating your
fields in the Designer View, you can move
forward with
1. Creating you database table or
2. Setting up your form

2. Design your form

Create your database table

1. Save and close your form,


2. In the Form Manager click the form for
which you want to create the database table
and
3. Click on the Create table button
4. In the Create table Panel, please unchecked
the Submit Field which is not necessary from
the field list
5. Click on the Save button
6. Your database table is created
7. Go back to the Forms manager
8. Open your form
9. Go to the Setup tab

2. Setup your form

Setup tab
Add the needed actions to your form

2. Setup your form

Setup tab : add a DB Read Action


Fill-in the Basic tab fields accordingly

Table Name

2. Setup your form

Setup tab : add a DB Read Action


Fill-in the Basic tab fields accordingly

2. Setup your form

Setup tab : add a DB Read Action


Do not change the values in the External
Database tab

2. Setup your form

Setup tab : add a Custom Code Action (On found)


Fill-in the Content field
(copy/paste the PHP code and adapt)

<?php
$user = JFactory::getUser();
("server, "username", "password", "databasename");

$con=mysqli_connect("server, "username",
"password", "databasename");
// Check connection
if (mysqli_connect_errno())
{
echo "Error: " . mysqli_connect_error();
tablename
}
$FormData = mysqli_query($con,"SELECT * FROM
"tablename" WHERE user_id=".$user->get("id")."
tablename
ORDER BY id DESC LIMIT 1");
$form->data["userID"]=$user->get("id");
$line = mysqli_fetch_array($FormData);
$checkbox1=$line['checkbox group name'];
$pieces = explode(",", $checkbox1);
$form->data["checkbox group name"] = $pieces;
$checkbox2=$line[checkbox group name'];
$pieces = explode(",", $checkbox2);
$form->data["checkbox group name"] = $pieces;
?>

2. Setup your form

Setup tab : add a DB Save Action (On not found)


Fill-in the Basic tab fields accordingly

Create If not Exists

Table Name

2. Setup your form

Setup tab : DB Save Action


Fill-in the External Database tab fields
accordingly

Host
Table Name
Username
Password

Table Name

2. Setup your form

Setup tab : add a Custome Code Action (On load)


Fill-in the Action Label and the Content field
accordingly
If user already filled in the form then fields will be prepopulated

<?php
$user = JFactory::getUser();
$con=mysqli_connect("server, "username",
"password", "databasename");
// Check connection
if (mysqli_connect_errno())
{
echo "Error: " .
mysqli_connect_error();
}
$FormData = mysqli_query($con,"SELECT * FROM
"tablename" WHERE user_id=".$user->get("id")."
ORDER BY id DESC LIMIT 1");
$form->data["userID"]=$user->get("id");
$line = mysqli_fetch_array($FormData);
$checkbox1=$line['checkbox group name'];
$pieces = explode(",", $checkbox1);
$form->data["checkbox group name"] = $pieces;
$checkbox2=$line['checkbox group name'];
$pieces = explode(",", $checkbox2);
$form->data["checkbox group name"] = $pieces;

2. Setup your form

Setup tab : add HTML (Render Form) (On load)


Fill-in the fields accordingly

2. Setup your form

Setup tab : Handle Arrays (On submit)


Do not change the values

2. Setup your form

Setup tab : add a DB Save Action (On submit)


Fill-in the Basic tab fields accordingly

Save/Update

name
Table Name

<?php
return array("user_id" => $form->data["userID"]);
?>

2. Setup your form

Setup tab : add a DB Save Action (On submit)


Fill-in the External Database tab fields
accordingly

Host
Table Name
Username
Password

Table Name

2. Setup your form

Save your form


When you have finished to setup your form,
please save your form. You can now for
example

1. Test your form by clicking the Test form


Button
2. Create an article, add
{chronoforms5}Nameofyourform{/chron
oforms5}
in it and publish it.

Das könnte Ihnen auch gefallen