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

    I'm trying to make a checkbox to send a cc using formit forms.

    [[!FormIt?
    	&hooks=`email`
    	&emailSubject=`Getting my checkbox to work`
    	&emailCC=`[[!+fi.cc:is=`on`:then=`[[+yourEmail]]`]] `
    	&validate=`yourEmail:email:required`
    ]]
    	<form action="[[~[[*id]]]]" method="post">
    		<input type="text" id="yourEmail" name="yourEmail">
    		<input type="checkbox" name="cc" id="cc">
    		<button>Let's do this!</button>
    	</form>
    


    Tried this without succes. Any help is appreciated!

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

      • 3109 ☆ A M B ☆
      • 894 Posts
      FormIt handles check boxes and radios differently look at this page of the docs so you can set it up correctly.

      http://rtfm.modx.com/display/ADDON/FormIt.Handling+Selects%2C+Checkboxes+and+Radios

      Good Luck.
        Benjamin Marte
        Interactive Media Developer
        Follow Me on Twitter | Visit my site | Learn MODX
        • 27437
        • 49 Posts
        Thanks, I've seen that page and according to that page I adapted my code
        <!-- This would also work -->
           <option value="yellow" [[!+fi.color:is=`yellow`:then=`selected`]]>Yellow</option>

        But nesting it in formit doesn't seem to work. I can't imagine i'm the first one to want to achieve this.
        • discuss.answer
          • 27437
          • 49 Posts
          So actually it's not hard to make a custom hook for it. If you use it you might wanna change some values and be sure to put it before the email hook.

          The snippet: checkboxCC
          <?php
          $cc = $hook->getValue('cc');
          if (!$cc) {
          	$email = ""; 
          } else {
          	$email = $hook->getValue('yourEmail');
          }
          $hook->setValue('emailCC', $email);
          return true;
          


          How to use it:
          [[!FormIt?
              &hooks=`checkboxCC,email`
              &emailSubject=`Getting my checkbox to work`
              &emailCC=`[[+emailCC]]`
              &validate=`yourEmail:email:required`
          ]]
              <form action="[[~[[*id]]]]" method="post">
                  <input type="text" id="yourEmail" name="yourEmail">
                  <input type="checkbox" name="cc" id="cc">
                  <button>Let's do this!</button>
              </form>
            • 3109 ☆ A M B ☆
            • 894 Posts
            Yes hooks execute in the order they are in the &hooks property, I explain that and a few other things in my FormIt tutorial which might be helpful.

            Glad you got it sorted out, good luck.
              Benjamin Marte
              Interactive Media Developer
              Follow Me on Twitter | Visit my site | Learn MODX