Forums

Wizard Custom : fill dropdown list with data, and other...

V@lentine 13 Nov, 2009
Hello,

I want to use Joomla and Chronoforms to develop an Intranet application (which now exists on MS-Access but is getting old and slow).
I want to try to do this with Joomla and Chronoforms because I am alone to develop this, and many things already exist on these systems (user management, interface and menus, form management). I could do all this by hand but I don't want to spend the next 10 years on this !!
I need to do some special things, and as I am new to Chrono Forms and not a native English speeker, I need your help.

I would like to do the following (for a start) :
- fill my drop down list with a SELECT request from a database
- change the order Cancel and Submit buttons (have Cancel and then Submit from left to right)
- get more information on how to execute PHP code on Submit (insert data in a database, calculate things...)

Any help would be graceful !

Valentine, France
nml375 13 Nov, 2009
Hi Valentine,
Lets see if we can get you started with this, shall we?

First item on the list, the database query:
<?
// Get the database object
$db =& JFactory::getDBO();

// Build the query
$query = sprintf('SELECT * FROM %s',
  $db->nameQuote('#__mytable')
);
// The nameQuote method is used to properly quote any table names to avoid SQL injection attacks. 
// The #_ prefix will be replaced with the Joomla database prefix as set in system setup (usually 'jos').

// Load the query and fetch the result
$db->setQuery($query);
$items =& $db->loadObjectList();
?>
...
<select name='databaseoption'>
<?
  foreach ($items as $item)
  {
    echo "<option value='" . $item->something. "'>" . $item->otherthing . "</option>";
  }
?>
</select>

A few explanations might be in order, I suppose:
This code assumes there are atleast two columns in your database called 'something' and 'otherthing', and assumes your database table is named jos_mytable. The loadObjectList() method returns an array with objects representing the result of the query, where each column in your table is represented by an object property.

I use sprintf() to build the query, although this could be done 'inline' or hardcoded. Imo easier to read and debug this way.

Next:
Changing the order of the buttons..
I assume you've used the Form Wizard to create your form, where this order is fixed. However, id you "manually" edit the form instead, you get access to the raw html/php-code of the form. You'll need to do this in order to implement the code in the previous section anyway. Head to the Form Code tab, and you'll find the proper entry box. Locate the submit and reset inputs, and swap them around.

I'll get to the remaining points on your list later on tonight
/Fredrik
nml375 13 Nov, 2009
Hi again,
For the next point, executing some php-code on-submit:
This part gets somewhat more complex, as there are several places where you may inject your php-code, depending on what you intend to achieve.

"insert data in a database":
For this, I'd recommend the DB Connection feature of ChronoForms, which will automate most of the process.
For trivial cases, there's the #5 "Saving data to the Database" tutorial. It's written for an older version of ChronoForms, but most of the actions are the same, although the newer interface for creating the database table can be confusing/misleading (green bar with red cross means this field is enabled). Also, the names of the table fields must match the names of the form inputs, and may not contain spaces or dashes.

To validate submitted data, there's the Serverside Validation, which allows you to run several tests on the submitted data, and decide if the processing should continue or abort.

For calculations, you could use the "on submit - before email" and "on submit - after email" entries. The exact code to be used would depend on exactly what you'd like to do. You could use pretty much any valid PHP-code, although I recommend using the Joomla API.
If you could elaborate what different tasks you need to do, I could probably create some suitable examples for you.

/Fredrik
V@lentine 16 Nov, 2009
Hello,

Thanks for you detailled reply.
I am testing another component for Joomla "Sourcerer" which allows me to add PHP in my articles.
I think I'll manage better to get what I want with that. if not, I'll come back to Chronoforms.

Best regards

Valentine
V@lentine 17 Nov, 2009
Thanks a lot, I just found the "form code tab" I had not found before !
Forget my previous message, this Chronoforms is really powerful.
This topic is locked and no more replies can be posted.