Forums

Email verification interrupts with the flow of PHP code

upriidu 03 Aug, 2009
I have a form that serves the purpose of providing an "order id" (as cf_id from the table) and a "random verification number" (a hidden field in the table, which stores a randomly created code) to the users after initial information is entered into the form and submitted. This info is displayed on the web after submitting and also sent my e-mail. I have the e-mail set up and everything is working until I activate email verification plugin. With the plugin, I do manage to verify the mail and add the flag into the database, but the order id and verification code is no longer being e-mailed to the user nor is the random code stored in the database. How can I use the e-mail verification and not interrupt the way this form works?

My form link: http://www.megaherts.ee/index.php?option=com_chronocontact&chronoformname=example (without verification)
Copy of the above form with verification plugin: http://www.megaherts.ee/index.php?option=com_chronocontact&chronoformname=example2

My form looks like this:
<div class="form_item">
  <div class="form_element cf_heading">
    <h1 class="cf_text">Example</h1>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Name</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_1" name="text_1" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Mail</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_2" name="text_2" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<input value="" id="hidden_4" name="hidden_4" type="hidden" />

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_5" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>


In Onsumbit - before email, I have the following code that generates the random-code into the database:
<?php
    $db =& JFactory::getDBO();
    do {
      $hidden_4 = generateIdent();
      $query = "
        SELECT COUNT(*)
          FROM # `mhz_chronoforms_example`
          WHERE `hidden_4` = $hidden_4 ";
      $db->setQuery($query);
    } while ( $db->loadResult() > 0 );
    JRequest::setVar('hidden_4', $hidden_4, 'post');
    /**
    * function to generate a random alpha-numeric code
    * using a specified pattern
    *
    * @param $pattern string
    *
    * @return string
    */
    function generateIdent($pattern='AA9999A')
    {
       $alpha = array("A","B","C","D","E","F","G","H",
        "J","K","L","M","N","P","Q","R","S","T","U","V","W",
        "X","Y","Z");
      $digit = array("1","2","3","4","5","6","7","8","9");
      $return = "";
      $pattern_array = str_split($pattern, 1);
      foreach ( $pattern_array as $v ) {
        if ( is_numeric($v) ) {
          $return .= $digit[array_rand($digit)];
        } elseif ( in_array(strtoupper($v), $alpha) ) {
          $return .= $alpha[array_rand($alpha)];
        } else {
          $return .= " ";
        }
      }
      return $return;
    }
    ?>


Data storage is enabled, saving data is set to before e-mail.

In OnSubmit - after email I have the following (and also in my e-mail template):
Your order ID: <?php
$MyForm =& CFChronoForm::getInstance();
$data = $MyForm->tablerow['mhz_chronoforms_example'];
?>
 <div class="form_element cf_text"> <span class="cf_text"><?php echo $data->cf_id; ?></span> </div>
 <div class="cfclear"> </div>

Verification code: <?php
$MyForm =& CFChronoForm::getInstance();
$data = $MyForm->tablerow['mhz_chronoforms_example'];
?>
 <div class="form_element cf_text"> <span class="cf_text"><?php echo $data->hidden_4; ?></span> </div>
 <div class="cfclear"> </div>

Thank You


Run order is as follows:
Autogenerated block: 2
OnSubmit block: 3
Plugin block: 1

I have been trying to play around with the run-order (setting plug-in block as the last one) with no success. Basically I want to have the verification process happening after the form is being fully and successfuly completed.
GreyHead 07 Jul, 2010
Hi upriidu,

If you don't have 'Send Emails' set to 'Yes' on the Form General Tab then the OnSubmit Before Email box is not executed. So you need to move your code generation to the OnSubmit After Emails Box which is always executed.

I think that the Run Order sequence then needs to be:

1) OnSubmit block (to generate the code)
2) Autogenerated code (to save the results to the database
3) Plugins to do the email verification

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