Add additional information to database

twi 07 Jul, 2009
I'm trying to accomplish something and I think I know how to do it, but just need some additional information. I have a form that when filled out it is both emailed and it is saved to a database. Both of these things work well, however I need to add some additional information to the database after the form is submitted. Basically it is a field that will be generated based upon fields that are entered by the person filling out the form. My problem is getting it to add this field to the database and the email. Any suggestions? The database part seems easy if I can find out how to get the unique id that is generated, but I'd also like to have this field added in the email that is sent out.

Also after creating a table and everything for my form and getting it working. If I add a new field to my form how do I get it to update and start sending that field to the database?
GreyHead 07 Jul, 2009
Hi twi,

Add a hidden field to your Form HTML with no value
<input type='hidden' name='new_field' value='' />


Add a new column to your database table with PHPMyAdmin or something similar (or drop and re-create the table if there is no important data in it).

Add the code to create the value in the OnSubmit Before box
<?php
$new_field = . . . //some code 
JRequest::setVar('new_field', $new_field, 'post');
?>


That should be all

Bob
twi 07 Jul, 2009
I understand hidden inputs in form. I'll explain a little better. I have an employment application for my company. We have several retail stores spead out over 2 States currently. In the application, the applicant fills out a zipcode field and a field that asks how far they are willing to commute. Based on these two fields I can call a function to evaluate them and decide what locations they'd be willing to work at. My problem is, I would have to do this after the submit, but before the email sent out. If I'm correct in thinking that, then to add to the database I'd have to know the unique id that is generated, and i'm not sure how to get it in the email at that point either.

Thanks for the suggestions.


**added thought.
After I hit the submit button I looked at the code you just gave me for adding a new datafield. I should be able to use that same code to accomplish this?
GreyHead 07 Jul, 2009
Hi twi,

The method I gave you will do exactly what you want. Code in the OnSubmit Before box is executed after the form is submitted and before the email is sent or the data is saved to the database table.

You don't need to know the record id as the field value will be saved along with the other form data.

Bob
twi 07 Jul, 2009
And the last question. In that code the part where you have "new_field" would but the same value as what the coloumn name is in the database. And in the email template would the same value I'd put the in {} so it would show up there?

Thanks,

Steven
GreyHead 07 Jul, 2009
Hi twi,

Yes, it doesn't matter what the name is, but the hidden field, the JRequest::setVar and the database column name should all be identical.

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