We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    Not sure how I've broken my Formit form, but after a way long time of staring at my code, I still can't seem to see how I've screwed things up.

    What I had originally tried to do (and failed at), was to try to take a site visitor's email information (from the email field of the form, called "email_contact") and have it appear in the notification email's "From" address. In other words, when the site editor receives a notification email alerting him/her that they just had someone fill out the form, instead of the email showing that it came from the system, it would seem like it came directly from the site visitor. As a result, the editor would be able to hit the reply button and it would already be addressed to the site visitor's email address (hope that made sense).

    I mistakenly added this property to the formit call:

    emailReplyTo=`email_contact`


    Anyway, that didn't work, so I tried to normal the code up by taking it out. The problem I'm writing about is that now, whenever I test the form, I receive two emails, both duplicates. The only difference between the two is that one comes in as I want it to, in other words, with the visitor's email in the "From" part of the email and the "To" part showing the email from the system settings.

    The second email comes in with the visitor's email within the "From" part of the email and the "To" part showing both the visitor's email and email in the system settings.

    The confirmation email now no longer works. And, of course, I only want one notification email to come in.

    My FormSave component now saves two entries, both duplicates.

    I tried the following:

    1. Manually deleting the property I had originally added to the Formit call.

    2. Clearing site cache.

    3. Deleting all the cache within core > cache. Actually, I created a whole new directory called cache and made it writable, just to be sure it was empty.

    4. Uploaded a copy of a database dump I had of the site, just to make sure the code within the control panel was as it was a few days ago.

    5. Went to the error log and I see this:

    [2013-03-18 16:38:15] (ERROR @ /index.php) An error occurred while trying to send the email:


    ...over and over, although some mail is being sent, with no details about what error is being created. I think the error originates in the snippet I mention below, in step 4, if that helps.

    6. If I take out the "emailUser_contact_page" hook out of the chain, the second email is still sent, although it only shows one email address in the "To" part of the email.

    Anyway, I can't seem to be able to revert the form to work the way it did before this problem started. Where can the problem be? How and where is the system holding on to the problem code?

    My setup is as follows:

    1. The form code looks like this:

    [[!FormIt?  
    &hooks=`spam,hook.RampartFormIt,FormSave,email,emailUser_contact_page,redirect`
    &submitVar=`contact_page`
    &emailSubject=`Submission from The Contact Us Page on the Company Website`
    &emailTpl=`EmailChunk_contact_page`
    &emailTo=`[email protected]`
    &redirectTo=`28`
    &fsFormTopic=`Contact Page`
    &fsFormFields=`firstName-contact,lastName-contact,street_address-contact,city_town-contact,state-contact,zipcode-contact,telephone-contact,email_contact,text-contact` 
    &validate=`firstName-contact:required,
    lastName-contact:required,
    street_address-contact:required,
    city_town-contact:required,
    state-contact:required,
    zipcode-contact:required,
    telephone-contact:required,
    email_contact:required`
    ]]
    
    [[!+fi.error.error_message:notempty=`
    <p>[[!+fi.error.error_message]]</p>
    `]][[!+fi.error.rampart]]
    
    
    <form class="form" action="[[~[[*id]]]]" method="post">
    
    <div id="contact_page_form_container">
    <h2>Your Information</h2>
    
    <div id="contact_page_form_name">
    <input name="nospam:blank" type="hidden" />
    <div id="contact_page_form_first_name">
    <label for="firstName-contact">
    * First Name:
    <span class="error">[[+fi.error.firstName-contact]]</span></label>
    <input id="firstName-contact" name="firstName-contact" type="text" value="[[+fi.firstName-contact]]" />
    </div><!-- /contact_page_form_first_name -->
    
    <div id="contact_page_form_last_name">
    <input name="nospam:blank" type="hidden" />
    <label for="lastName-contact">
    * Last Name:
    <span class="error">[[+fi.error.lastName-contact]]</span></label>
        <input id="lastName-contact" name="lastName-contact" type="text" value="[[+fi.lastName-contact]]" />
    </div><!-- /contact_page_form_last_name -->
    <div style="clear: both;"></div>
    </div><!-- /contact_page_form_name -->
    
    <div id="contact_page_form_address">
    
    <div id="contact_page_form_street_address">
    <label for="street_address-contact">* Street Address:<span class="error">[[+fi.error.street_address-contact]]</span></label><br />
    <input name="street_address-contact" type="text" id="street_address-contact" value="[[+fi.street_address-contact]]">
    </div><!-- /contact_page_form_street_address -->
    
    <div id="contact_page_form_city_town">
    <label for="city_town-contact">* City/Town:<span class="error">[[+fi.error.city_town-contact]]</span></label><br />
    <input name="city_town-contact" type="text" id="city_town-contact" value="[[+fi.city_town-contact]]">
    </div><!-- /contact_page_form_city_town -->
    
    <div id="contact_page_form_state">
    <label for="state-contact">* State:<span class="error">[[+fi.error.state-contact]]</span></label><br />
    <div id="state_select_div">
    <select name="state-contact" class="select_width">
    [[!FormItStateOptions? &selected=`[[!+fi.state-contact]]`]]
    </select>
    </div><!-- /state_select_div -->
    </div><!-- /contact_page_form_state -->
    
    <div id="contact_page_form_zipcode">
    <label for="zipcode-contact">* Zipcode:<span class="error">[[+fi.error.zipcode-contact]]</span></label><br />
    <input name="zipcode-contact" type="text" id="zipcode-contact" value="[[+fi.zipcode-contact]]">
    </div><!-- /contact_page_form_zipcode -->
    
    <div id="contact_page_form_phone_number">
    <input name="nospam:blank" type="hidden" />
    <label for="telephone-contact">
    * Telephone:<span class="error">[[+fi.error.telephone-contact]]</label>
    <input id="telephone-contact" name="telephone-contact" type="text" value="[[+fi.telephone-contact]]" />
    </div><!-- /contact_page_form_phone_number -->
    
    <div id="contact_page_form_email">
    <label for="email_contact">* Email Address:<span class="error">[[+fi.error.email_contact]]</span></label><br />
    <input name="email_contact" type="text" id="email-contact" value="[[+fi.email_contact]]">
    </div><!-- /contact_page_form_email -->
    
    </div><!-- /contact_page_form_address -->
    <div style="clear: both;"></div>
    
    <div id="contact_page_form_comments">
    <label for="text-contact">Comments:</label><br />
    <textarea name="text-contact" Id="text-contact">[[+fi.text-contact]]</textarea><br>
    </div><!-- /contact_page_form_comments -->
    
    <div id="contact_page_form_comments_submit_button">
    <input type="hidden" name="subject" id="subject" value="Submission from The Contact Us Page on the Company Website" />
    <input name="contact_page" class="contact_page_form_submit" title="contact_page" type="submit" value=" ">
    </div><!-- /contact_page_form_comments_submit_button -->
    
    </div><!-- /contact_page_form_container -->
    </form>



    2. The email tpl, called "EmailChunk_contact_page" contains this:

    [[+firstName-contact]] [[+lastName-contact]] ([[+email_contact]]) wrote:<br /><br />
    
    Message: [[+text-contact]]
    
    <br /><br />
    
    First Name: [[+firstName-contact]]<br />
    Last Name: [[+lastName-contact]]<br /><br />
    Street Address: [[+street_address-contact]]<br />
    City/Town: [[+city_town-contact]]<br />
    State: [[+state-contact]]<br />
    Zipcode: [[+zipcode-contact]]<br />
    Phone Number: [[+telephone-contact]]<br />
    Email Address: [[+email_contact]]


    3. The confirmation email tpl, called "ConfirmationTpl-contact-page" contains this:

    <p>Hello,[[+firstName-contact]] [[+lastName-contact]]:</p>
    
    <p>Thank you for contacting us through the XXXX website!  We will be getting back to you shortly.</p>


    4. Finally, I have a snippet to control the confirmation email, called "emailUser_contact_page" that contains this:

    <?php
    //configuration
    $mailFrom = $modx->getOption('emailsender'); //OR USE YOUR OWN;
    $mailFromName = $modx->getOption('site_name'); //OR USE YOUR OWN;
    $mailSender = $modx->getOption('site_name'); //OR USE YOUR OWN;
    $mailSubject = 'Submission from The Contact Us Page on the Company Website';
    $mailReplyTo = $mailFrom;
    
    //get fields values so they can be replaced in the email chunk
    $confirmationFields['firstName-contact'] = $scriptProperties['fields']['firstName-contact'];
    $confirmationFields['lastName-contact'] = $scriptProperties['fields']['lastName-contact'];
    
    //get user's email
    $mailTo= $scriptProperties['fields']['email_contact'];
      
    $text = $modx->getChunk('ConfirmationTpl-contact-page', $confirmationFields);
      
    $modx->getService('mail', 'mail.modPHPMailer');
    $modx->mail->set(modMail::MAIL_BODY,$text);
    $modx->mail->set(modMail::MAIL_FROM,$mailFrom);
    $modx->mail->set(modMail::MAIL_FROM_NAME,$mailFromName);
    $modx->mail->set(modMail::MAIL_SENDER,$mailSender);
    $modx->mail->set(modMail::MAIL_SUBJECT,$mailSubject);
    $modx->mail->address('to',$mailTo);
    $modx->mail->address('reply-to',$mailReplyTo);
    $modx->mail->setHTML(true);
    
    if (!$modx->mail->send()) {
        $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
    return false;
    }
    
    $modx->mail->reset();
    
    return true;


    5. Running the following:

    Formit 2.1.2.
    MODx Revolution 2.2.6-pl


    Thank you all in advance. [ed. note: waizen last edited this post 13 years, 6 months ago.]