Forums

not fully understanding OnSubmit()

glens1234 25 Feb, 2008
Hi there.

My html form submits the data to a php action page


<form method="post" action="process_app_form.php">
....etc


However, in the general section of the form builder it states...

"Form tag attachment:
something like onSubmit()"

Im not really sure what this means! What to i have to add here?

Secondly...

How do i open the database connection.
I have setup my table in the joomla database.
Do i simply use..

include 'configuration.php'


Im slightly confused about how to specify the relative path of this file!

Im very new to php/joomla etc so i hope this makes sense.

cheers!
GreyHead 25 Feb, 2008
Hi glens1234,

To redirect to a php action page put the URL in the Redirect URL box on the Form URLs tab. Note that if you do this ChronoForms will never see the submitted form and so can't do anything with the data.

What are you trying to do with the database? - configuration.php is loaded by Joomla you don't need to touch it.

Bob
glens1234 26 Feb, 2008
Thanks bob

All im trying to do is enter the data from the form into the database. I am using a list box menu on the form and therefore i have used the php implode() function to insert the array into a varchar() field.

Lets say i copy and paste the html form code into the html code section of the chrono module.


<!--- onyl display form if it has not already been submited --->
<?php
if (!isset($_POST['submit'])) {
?> 

<body>
   <form method="post" action="process_app_form.php">
      <table border="0" cellspacing="0" cellpadding="2">
           <tr>
            
            <td>Name:</td><td><input type="text" name="Name" maxlength="30" size="26" /></td>
         </tr>
		
		<tr><td>Languages Spoken</td>
		<td><select name="languages_spoken[]" multiple size="5">
		<option value="English">English</option>
		<option value="French">French</option>
		<option value="Spanish">Spanish</option>
		<option value="German">German</option>
		</select></td>
           
		   </tr>
		   <tr>
		    <td><input type="submit" name="Submit"
               value="Submit"></td>
         </tr>
      </table>
   </form>
   <br />

</body>
</html>
   <?php
   }
   ?>
   



Then i paste the php (action page) code into the "on Submit code" section.


<?php
   
$name = stripslashes($_POST['Name']);
$languages_spoken = $_POST['languages_spoken'];

$lang_spoken = implode(" ", $languages_spoken);
$query = "INSERT INTO translators (name,lang_spoken) VALUES ('$name', '$lang_spoken') "; 

mysql_query($query) or die('Error, insert query failed '.mysql_error());

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

echo "Thank you ". $name .". We will be in contact with you shortly";

?>



As you can see in the html code i am using process_app_form.php as the form action. However, obviously this file does not exist anymore since i have copied and pasted the code.

So do i simply take the "action="process_app_form.php"" part out?
Do i have to add any code in the "on Submit code" section?

cheers!

Post edited by: glens1234, at: 2008/02/25 19:25<br><br>Post edited by: glens1234, at: 2008/02/25 19:26
GreyHead 26 Feb, 2008
Hi glens1234,

OK, first you don't want the form tags in the HTML code bos so put this there:
<table border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td>Name:</td>
    <td><input type="text" name="Name" maxlength="30" size="26" /></td>
  </tr> 
  <tr>
    <td>Languages Spoken</td>
    <td><select name="languages_spoken[]" multiple size="5">
      <option value="English">English</option>
      <option value="French">French</option>
      <option value="Spanish">Spanish</option>
      <option value="German">German</option>
      </select></td>
  </tr>
  <tr>
    <td><input type="submit" name="Submit" value="Submit"></td>
  </tr>
</table>
this will generate your form.

If you want to show a Thank you page then you can put the code for that in the 'OnSubmit after email' box:
<p>Thank you <php echo $_POST['name'] ?> We will be in contact with you shortly.</p>
To save the data to a ChronoForms Joomla database you just have to click Create Table in the Forms manager and the data will be saved for you.

Most likely this will do what you need, if not please come back and ask again.

Bob<br><br>Post edited by: GreyHead, at: 2008/02/25 21:05
glens1234 26 Feb, 2008
hi.

i have removed the form tags.

I have also setup the table using "create table"

When i submit the form and click on the "show saved data" link, the data is there.

So all is good apart from a few things!

I need access to this data after it has been entered into the database. However, i cannot seem to find the table, that it created in the "joomla" database.


Also, as mentioned my script uses the implode() function in order to store the list box values as a single string.

So what method does Chrono forms use to store this array?

This is really important as my search program also uses the implode() function. i.e


$languages_spoken = $_POST['languages_spoken'];
$lang_imploded = implode(" ", $languages_spoken);
$query = "SELECT * FROM employees WHERE lang_spoken LIKE '$lang_imploded%'";

$result = mysql_query($query) or die ('Error, insert query failed'.mysql_error());

// Print out the contents of the entry
$lang_array = explode(" ", $lang_spoken);

$num_rows = mysql_num_rows($result); 
print "There are $num_rows records.<P>"; 
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n"; 

?>



Thanks again bob.
GreyHead 26 Feb, 2008
Hi glens1234,

If you look at the Autogenerated tab in ChronoForms you'll see the SQL code that's being used to save the data. The database table is in there - something like #__chronocontact_1 I think.

If you know what you are doing then you can change the SQL here to save to another table or to modify the values. You can also pre-process the results in either of the OnSubmit boxes (either save the modifies results in the $_POST array, or change the variable names in the SQL).

the implode & explode functions simply turn and array into a string and vice versa (I forget which is which) so you can always undo the process. Ah! I read your code more closely and see that you are relying on the sequence in the string. (This should be OK but I'm a more robust way of coding this would be to use a second table with fields for employee_id & language_id, search this for the combination of languages you need.)

To see exactly what ChronoForms is saving click the 'See form data' at the right in the Forms Manager forms list.

Bob

PS Ideally you should never need to call mysql functions directly in Joomla - there's a good set of Joomla functions that can so much of this management for you.
glens1234 26 Feb, 2008
ah! yes. that was what i was after.

I thought i looked through all of those tabs though.

The table name was jos_chronoforms_1 for future ref!

Anyway, despite my confusion it's a cool application!

cheers!
This topic is locked and no more replies can be posted.