Forums

Different values to email and db from the same form.

megant 17 Feb, 2010
Hi,

I made a registration form in multiple languages with ChronoForms and Joomfish. My purpose is to send confirmation mail containing user registration data in the language of the registrant, but I also need inserting all data into the specific table in the admin's language. The values of the form are basically in admin's language. I wrote a cycle in the "onSubmit e-mail" field, where PHP replaces every form values in $_POST variable according to the user specific language. It works. My problem is with the db insertion. The forms setting are:

Enable Data storage: Yes
Saving Data/Emails order: Before Email
RunOrder:

Order of Autogenerated block 2
Order of OnSubmit block 3
Order of Plugins block 1

The table insertion doesn't seem to work (ChronoForms cannot write the translated values into MySQL enum fields which accepts only values in the admin's language, eg 'yes','no'), maybe the onSubmit block runs earlier than the insertion. What is the problem?
GreyHead 17 Feb, 2010
Hi megant,

The problem is that the OnSubmit Before code is run before the DB code. You can see the sequence here:
		/**
		 * If there are no errors and e-mail is required then build and send it.
		 */
		if ( ($MyForm->formrow->emailresults) && !$MyForm->error_found && !$MyForm->stoprunning ) {		
			//run before submit code
			if(!$MyForm->haltFunction["onsubmitcodeb4"]){
				$MyCustomCode->runCode( 'onsubmitcodeb4' );
				if($MyForm->showFormErrors($MyForm->formrow->name)){
					$MyForm->showForm($MyForm->formrow->name, $posted);
					return;
				}
			}
			if(!$MyForm->haltFunction["autogenerated_before_email"]){
				$MyCustomCode->runCode( 'autogenerated', 'before_email' );
			}		
			//send emails
			if(!$MyForm->haltFunction["emails"]){
				$emails_result = $MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails);		
			}	
		}	
I think that I would create a second set of variables for the email to avoid these problems: or you could hack the code :-(

Bob
megant 17 Feb, 2010
Well, where/how can I create a "second set of variables" without hacking the code?
GreyHead 17 Feb, 2010
Hi megant,

You can add a new variable in the OnSubmit before box:
<?php
$lang array = array('yes' => 'ja', 'no' => 'nein', 'maybe' => 'vielleicht');
$check_1_gb = JRequest::getString('check_1', '', 'post');
JRequest::setVar('check_1_de', $lang_array[$check_1_gb]);
?>


Then you can use the two sets to save and email.

Needs a little thinking throuhg (and this maynot be the best way to code it) but it will work OK.

Bob
megant 17 Feb, 2010
Yes, I did like that before. Maybe you just didn't understand my problem exactly. So I filled up the onSubmit field with similar code (I also named the $lang_array as you 😀 ) and set up the RunOrder: 1st plugin block, 2nd autogenerate block, 3rd onSubmit block, so ChronoForms should have made the db insertion first and executed the onSubmit block after that, but it didn't work. I think the only way is hacking :?
GreyHead 17 Feb, 2010
Hi megant,

I'm pretty certian that my suggestion will work without any hacking or changing the run order at all. You will need to set one set of variables to use in the email and the other set for the db save.

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