I have a form that (among other things) asks for the user's zipcode. In the code section "On Submit code - before sending email" I query a zipcode table which gives me the users $city and $state. At this point I assumed that I would be able to just assign the $city and $state values to two hidden fields in the form.
like:
$_POST['hidden_0'] = $city;
$_POST['hidden_1'] = $state;or maybe:
JRequest::setVar('hidden_0',$city,'POST','true');When the email is sent the hidden_0 and hidden_1 fields are empty and the registration plugin does not receive the values either. I tried running the same basic code in the Validation tab and got the same results. I must have some false assumptions regarding the order of execution of something. A push in the right direction is appreciated!
Thanx!
-Dauk
As far as I can see that should work OK. Do you have Send Emails set to On in the General Tab? (If not then the OnSubmit before box doesn't run.)
Bob
<scratching head>
-dauk
form html:
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label">Click Me to Edit</label>
<input class="cf_inputbox" maxlength="150" size="30" id="text_0" name="text_0" type="text">
</div><div class="clear"> </div></div>
On submit code:
<?php
JRequest::setVar('text_0','this is new text','POST');
?>
This works OK for me. I edited your test form to add two output lines to the OnSubmit code
<?php
echo "_POST: ".print_r($_POST, true)."<br /><br />";
$array = $_POST;
$array['text_0'] = 'this is new text';
//JRequest::setVar($array, 'POST', true );
JRequest::setVar('text_0','this is new text','POST');
echo "_POST: ".print_r($_POST, true)."<br /><br />";
?>and when I submit the form I see this_POST: Array ( [text_0] => wserwer [68fd3a3fb70d82bba95c57adc5635920] => 1 )
_POST: Array ( [text_0] => this is new text [68fd3a3fb70d82bba95c57adc5635920] => 1 )
I think that your problem is that the email template fields are evaluated before the OnSubmit Before code has run. (Thst isn't necessarily helpful but it's how ChronoForms is set up.)
We've looked at this before and a workaround is to put a proxy (like ##zip##) in place in the email template and to use str_replace substitute it in the OnSubmit Before box. There's an example in this thread
Bob
-Dauk
Thanks for the help
-Dauk
I should say that I *really* do appreciate how flexible ChronoForms is! I mean, what other module allows you to 'roll-your-own-$whatever' like ChronoForms 😀
The term "enough rope to hang yourself with" comes to mind too.. but I prefer the positive spin
-Dauk!
PS: Here's the code^H^H^H^Hhack for interested parties
<?php
global $mainframe;
// Currently in: On Submit Code - before sending email
$username = $_POST['text_8']; //JRequest::getVar('text_8','','post'); //
$email = $_POST['text_1']; //JRequest::getVar('text_1','','post') ;//
$zipcode = $_POST['text_2']; //JRequest::getVar('text_2','','post') ;//
$DB =& JFactory::getDBO();
//verify that the username and email address are available
$query = "SELECT `username`,`email` FROM #__users WHERE `username` = '$username' OR `email` = '$email'";
$DB->setQuery($query);
$rows = $DB->loadObjectList();
$error = 0;
$error_ms = '';
foreach ($rows as $row)
{
if ($email == $row->email)
{
$error = 1;
$error_ms .= "An account already exists with the email: $email ($row->email) <br />";
}
if ($username == $row->username)
{
$error = 1;
$error_ms .= "An account already exists with the username: $username ($row->username) <br /> ";
}
}
$error_ms .= 'Please choose another or if this is your email just use the <a href="index.php/Lost-password.html">\'lost password\'</a> utility<br />';
if ($error > 0) {$error = 0; return $error_ms;}
$query = "SELECT * from zip_code WHERE `zip_code` = '$zipcode'";
$DB->setQuery($query);
$rows = $DB->loadObjectList();
$city = $rows[0]->city;
$state = $rows[0]->state_prefix;
// if the query failed then the zipcode must not be in our database
if ($city == '' || ! isset($city))
{
$error = "Please re-enter zipcode or entere a nearby zipcode.<br />The zip '$zipcode' does not exist in our database";
return $error;
}
$_POST['hidden_0'] = $city; //JRequest::setVar('hidden_0',$city,'post');//
$_POST['hidden_1'] = $state; //JRequest::setVar('hidden_1','post');//
//<START>We'll call the plugin ourselves MANUALLY w00t!
$formname = JRequest::getVar( 'chronoformname');
$query = "SELECT * FROM #__chrono_contact WHERE name='$formname'";
$database->setQuery( $query );
$rows = $database->loadObjectList();
$ava_plugin = 'cf_cb_registration';
if ($debug) {$mainframe->enqueueMessage("before query: ID: ".$rows[0]->id);}
$query = "SELECT * FROM #__chrono_contact_plugins WHERE form_id='".$rows[0]->id."' AND event='ONSUBMIT' AND name='".$ava_plugin."'";
$DB->setQuery( $query );
$plugins = $DB->loadObjectList();
if ($debug) {$mainframe->enqueueMessage('before plugins test count:'.count($plugins)." plugins");}
if(count($plugins)){
require_once(JPATH_SITE."/components/com_chronocontact/plugins/cf_cb_registration.php");
if ($debug) {$mainframe->enqueueMessage('loaded cf_cb_registration');}
${$ava_plugin} = new $ava_plugin();
$registry3 = new JRegistry();
$registry3->loadINI( $plugins[0]->params );
$params = $registry3->toObject( );
if ($debug) {$mainframe->enqueueMessage($ava_plugin .'->calling onsubmit');}
${$ava_plugin}->onsubmit( 'com_chronocontact', $params, $plugins[0] );
}
//<END>End of calling plugin code
print "
<p>Thanks for registering $_POST[text_7]! A confirmation email has been sent to $_POST[text_1]. Please read the email and follow the activation link to complete your registration.</p>
<p>*If you do not find the email in your INBOX then please make sure to check your spam filter/junk mail.</p>";
?>
Hmm, this workaround mostly works but doesn't get the revised $_POST values into the cf_cb_registration plugin only the email. Do you happen to have a workaround to get the values into the cf_cb_registration plugin? I'll look more closely at the $plugins array and see if I can update something there.
Thanks for the help
-Dauk
Hi dauk,
did you pay attention that there is some way to change the order or execution of the "onSubmit" code and the pugins..etc ? you have to know the correct order the code will use to run!
Regards
Max
-Dauk
Cheers
Max
