Create field data for database from multiple form fields

praymond 12 Mar, 2009
I've just found ChronoForms in the last week after FacileForms, Breezing forms and several other components. I had been a big fan of Facile Forms but it was limited in it's data structure. I'm so impressed with ChronoForms and ChronoConnectivity. A really good blend.

I built our sailing club's website some 4 years ago and I've now migrated to J1.5 and am now making some changes and improving the functionalty. I've built a regatta entry form for the club which includes some hidden fields and loads to a database table. What I want to do is concatentate the record ID + regattacode + sailnumber and post this in the email template as wel as load to the database table. The problem as I see it is the record ID doesn't get created unitl the Form action so the how can I create the "usercode" and load it to the table?
GreyHead 12 Mar, 2009
Hi praymond,

Using the Run Order tab you can have the database save execute before the email.

Bob
Max_admin 12 Mar, 2009
Hi, under the "auto generated" tab there is "saving data/emails order", set it to before email and use the $row_formname variable in the auto generated code to bring the record id!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
praymond 12 Mar, 2009
Hi Bob and Max,
Thank you for the quick response. OK, I'm not a programmer but can write some code so please bear with me on this.

Max, your suggestion is easy to understand as far changing the saving data/email order to 'Before Email'. That makes sense as my concatentated field value should be created before form submit. As far as getting the $row_formname variable in the auto generated code to bring the record id is this done in Form Code tab under Javascript oras PHP "On submit before sending email" or is it best done somewhere else?

Bob, I haven't played with Run Order yet so I'm guessing that the Run Order should now be:
1. Order of Plugins block
2. Order of Autogenerated block
3. Order ofOn Submit block.
Max_admin 13 Mar, 2009
Hi praymond,

the code in HTML/JS is what you see when the form loads, other code will run when form submits but with some order, you need to get the id of the record stored in the database to show in the email, then the record should be created before the email is sent, once you are connected to some table, a new code will be auto generated which will have a special variable name (object) which holds all the created record data, did you connect to some table ? show me your auto generated code!


Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
praymond 13 Mar, 2009
Max,

In Email Template:
If paying by EFT please use {EFTRef} as your reference.


I've got two hidden fields at end of Form HTML, the 'RegattaCode' and I'm declaring the 'EFTRef' field here as well with a Null value to start with. Is this OK?
<input value="DMR09" id="hidden_47" name="RegattaCode" type="hidden" />
<input value="" id="hidden_48" name="EFTRef" type="hidden" />



I'm using the database table Chronoforms creates for me and I want to use cf_id and not cf_user_id as the person submitting the form may not be a registered user. So EFTRef = RegattaCode + cf_id + SailNumber. Field 'SailNumber' is normal input field.

Autogenerated code is as follows:
<?php
		if($paramsvalues->dbconnection == "Yes"){
			$user = JFactory::getUser();			
			$row =& JTable::getInstance("chronoforms_RegattaEntryForm_v3", "Table");
			srand((double)microtime()*10000);
			$inum	=	"I" . substr(base64_encode(md5(rand())), 0, 16);
			JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
			JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
			JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", "" ));
			JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
			$post = JRequest::get( "post" , JREQUEST_ALLOWRAW );			
			if (!$row->bind( $post )) {
				JError::raiseWarning(100, $row->getError());
			}				
			if (!$row->store()) {
				JError::raiseWarning(100, $row->getError());
			}
			global $row_jos_chronoforms_RegattaEntryForm_v3;
			$row_jos_chronoforms_RegattaEntryForm_v3 = $row;
		}
		?>


Can you suggest what code I need and where to put this?
Thanks in advance
GreyHead 13 Mar, 2009
Hi praymond,

You will need to use the global variable $row_jos_chronoforms_RegattaEntryForm_v3 that ChronoForms creates in the AutoGenerated Code.

After the Autogenerated code has run - either in the email template or the OnSubmit After box depending on how you are sequencing things - you will need to add some code like this
<?php
global $row_jos_chronoforms_RegattaEntryForm_v3;
$code  = $row_jos_chronoforms_RegattaEntryForm_v3->RegattaCode;
$code .= $row_jos_chronoforms_RegattaEntryForm_v3->cf_id;
$code .= $row_jos_chronoforms_RegattaEntryForm_v3->SailNumber;
JRequest::setVar('EFTRef ','$code', 'post');
?>
Assuming that the sequence all works (I think it should but I'm not certain) then the correct value will appear in EFTRef after this.

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