We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37713
    • 17 Posts
    Hi,

    I am working on a page where I need a form that sends email to a person whom email address user fills in form, but there is also a option to send the email to the user himself too after checking a checkbox.

    I am not a programmer, so it's quite a struggle for me.

    I tried to create a snippet SendCc
    <?php
    $send = $hook->getValue('sendToMeToo');
    if ($send == 1)
    {    
        $userChoice = $hook->getValue('usremail');
        $choice = intval($userChoice); // convert string in integer
        $hook->setValue('emailAddress',$group[$choice]);
    }
    


    And here is my formit page:

    [[!FormIt?
        &hooks=`SendCc,spam,email,FormitSuccess`
        &emailTpl=`sentEmailTpl`    
        &emailTo=`[[+emailToSomeone]]`
        &emailCC=`[[+emailAddress]]`
        &emailFrom=`[email protected]`
        &emailMultiSeparator=`<br />`
        &submitVar=`submit`
        &validate=`usremail:email:required,
          emailToSomeone:email:required,
          yourMessage:required
        &errTpl=`<p class="error"><strong>[[+error]]</strong></p>`
        ]]
    
    <form id="contactForm" action="[[~[[*id]]]]#contactForm" method="POST">
    [[+success]]
                      
    <label for="emailToSomeone">E-mail to</label>
    <input type="text" name="emailToSomeone" id="emailToSomeone" placeholder="E-mail to" value="[[!+fi.emailToSomeone]]">
    [[+fi.error.emailToSomeone]]
                           
    <label for="yourMessage">Your Message</label> 
    <textarea name="yourMessage" placeholder="what do you want to say">[[!+fi.yourMessage]]</textarea>
    [[!+fi.error.yourMessage]]
    
    <label for="usremail">Tvůj e-mail</label>                   
    <input type="email" name="usremail" id="usremail" value="[[!+fi.usremail]]" placeholder="Your Email">
    [[+fi.error.usremail]]                     
                                                 
    <input type="checkbox" name="sendToMeToo" id="sendToMeToo" value="0" [!+fi.sendToMeToo:FormItIsChecked=`1`]] />
    <label for="sendToMeToo">Send me the copy of the form.</label>
    
    <input name="submit" type="submit" value="Send" />  
                                       
    </form>
    


    I tried to search everywhere, but couldn't find anything.
    Thanks.

    This question has been answered by fbasta. See the first response.

    [ed. note: fbasta last edited this post 7 years, 7 months ago.]
      • 28432
      • 372 Posts
      Hi,

      Maybe you can tried to do it directly in the formit call ?!

      [[!+fi.sendToMeToo:notempty=`&emailCC=`[[+emailAddress]]`]]


      And there you got an square bracket missing ;-)
      <input type="checkbox" name="sendToMeToo" id="sendToMeToo" value="0" [!+fi.sendToMeToo:FormItIsChecked=`1`]] />

      It should be
      [[!+fi.sendToMeToo:FormItIsChecked=`1`]]
        • 37713
        • 17 Posts
        Hi Steeve,

        thanks for helping out with this, I am no programmer, so I feel kind of lost.

        I tried your suggestion, so my formit call looks like this:

        [[!FormIt?
            &hooks=`spam,email,FormitSuccess`
            &emailTpl=`sentEmailTpl`    
            &emailTo=`[[+emailToSomeone]]`
            [[!+fi.sendToMeToo:notempty=`&emailCC=`[[+emailAddress]]`]]
            &emailFrom=`[email protected]`
            &emailMultiSeparator=`<br />`
            &submitVar=`submit`
            &validate=`usremail:email:required,
              emailToSomeone:email:required,
              yourMessage:required
            &errTpl=`<p class="error"><strong>[[+error]]</strong></p>`
            ]]
        


        The missing square bracket, was just a typo, when I was deleting classes, etc. from the elements to make the code more readable.

        Still not working though. Form is normally send, but the copy to the user who filled it not.

        I also tried to change the conditional you provided:
         &emailCC=[[!+fi.sendToMeToo:notempty=`[[+emailAddress]]`]]


        No luck either. Any other suggestions how to make this work ? smiley

        Thanks
        • discuss.answer
          • 37713
          • 17 Posts
          Ok, so I haven't been able to solve it just through the condition inside the Formit call but, after some more searching I found a topic on the forum and I was able to make it work through the custom hook in formit and snippet.

          Here is the link:
          https://forums.modx.com/thread/70551/using-formit-with-a-send-me-a-copy-checkbox