We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23831
    • 23 Posts
    Hello, does anyone here know how to make an email verification field? I have it set up right now so you have to actually put something there but it doesnt neccessarily need to be the same email address (kind of pointless really)... Below is a sample of my code. Please advise. Thanks!
    [+validationmessage+]
    <form id="eFeedBackForm" method="post" action="[~[*id*]~]" name="eFeedBackForm">
        
        <table>
        <tr>
        <td>
        <p><label accesskey="n" for="Name">First Name<span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="fname" size="15" maxlength="20" eform="First Name::1" /></p>
        </td>
        <td>
        <p><label accesskey="n" for="Name">Last Name<span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="lname" size="20" maxlength="20" eform="Last Name::1" /></p>
        </td>
        </tr>
        </table>
        <table>
        <tr>
        <td>
        <p><label accesskey="e" for="email">Company Name<span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="company" size="40" maxlength="40" eform="Company Name::1" /></p>
        </td>
        </tr>
        <tr>
        <td>
        <p><label accesskey="e" for="email">Job Title<span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="jobtitle" size="40" maxlength="40" eform="Job Title::1" /></p>
        </td>
        </tr>
        </table>
        <p><label accesskey="e" for="email">Email Address <span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="email" size="30" maxlength="40" eform="Your Email Address:email:1" /></p>
        <p><label accesskey="e" for="email">Verify your Email Address <span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="vemail" size="30" maxlength="40" eform="Your Email Address:email:1" /></p>
    
        <p><label accesskey="c" for="address">Street Address or PO Box <span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="address" size="30" maxlength="30" eform="Address::1" /></p>
        <p><label accesskey="d" for="city">City <span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="city" size="30" maxlength="30" eform="City::1" /></p>
        <p><label accesskey="d" for="city">State <span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="state" size="30" maxlength="30" eform="State::1" /></p>
        <p><label accesskey="d" for="city">Zip Code <span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="zipcode" size="10" maxlength="10" eform="Zipcode::1" /></p>
        <p><label accesskey="p" for="phone">Phone Number <span style="color: red; font-size: 10px;">*required</span></label>
        <br />
        <input type="text" name="phone" size="20" maxlength="15" eform="Phone Number::1" /></p>
        </p>
        
        <p><input type="submit" name="submit" value="Register!"></p>
    </form>
      • 3749
      • 24,544 Posts
      If you just need a simple contact form, you might look at SPForm (http://modxcms.com/extras.html?view=package/view&package=426). If you need something more complicated, check out eForm (http://modxcms.com/extras.html?view=package/view&package=123). Either snippet will verify the email for you (and a lot more -- e.g. spam protection).

      If you still want to roll your own, take a look at the code from one of the two snippets and see how they do it.

      Hope this helps. smiley
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 23831
        • 23 Posts
        Thanks for the reply. I was wondering though if there is a simple code to put in the second email field that would check to see if it was the same as the first? I just want to make sure they dont put two different emails or misspell one of them... If there is no code to add then its cool, Ill just go with what I have. Thanks.
          • 30223
          • 1,010 Posts
          [!eForm? &eFormOnValidate=`efCompareEmail` ....!]

          //<?php 
          if(!function_exists('efCompareEmail'){
            function efCompareEmail( &$fields, &$vMsg, &$rMsg, &$rClass ){
              if($fields['email'] != $fields['vemail']] ){
                $vMsg['email'] = 'Email fields are not the same';
                return false;
              }else return true;
            }
          }


          See eform documentation and the forums on how to include this function via an extra snippet.
            • 4310
            • 2,310 Posts
            If you’re not comfortable with using TobyL’s excellent method try the poor man’s alternative, add something like this to your form :
             
               			<label>Confirm Email *</label>
                		<input type="text" name="cemail" size="40" maxlength="40" eform="Confirm Email Address:email:1:Email address does not match:#EVAL if($_POST['email'] == $_POST['cemail'])return true; else return false;" />
            

            It simply compares the email & cemail fields.
              • 30223
              • 1,010 Posts
              Quote from: bunk58 at May 17, 2009, 08:47 AM

              If you’re not comfortable with using TobyL’s excellent method try the poor man’s alternative, add something like this to your form :
               
                 			<label>Confirm Email *</label>
                  		<input type="text" name="cemail" size="40" maxlength="40" eform="Confirm Email Address:email:1:Email address does not match:#EVAL if($_POST['email'] == $_POST['cemail'])return true; else return false;" />
              

              It simply compares the email & cemail fields.

              This will certainly work, but it will no longer validate for valid email addresses. i.e. email="johnywithoutanemail" & vemail="johnywithoutanemail" will validate as true.
                • 4310
                • 2,310 Posts
                Your right of course, but I made the assumption that the email field was already using eform’s built in email field validation wink
                  • 30223
                  • 1,010 Posts
                  Quote from: bunk58 at May 17, 2009, 09:59 AM

                  Your right of course, but I made the assumption that the email field was already using eform’s built in email field validation wink

                  When applying a custom validation in the "eform" attribute the build-in validation is skipped.