We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21671
    • 244 Posts
    Hey all,
    I’m trying to use the empty field snippet named checkField() that Susan produced.

    it is a snippet named echeckField. It’s code is :
    <?php
    function checkField(&$fields,&$vMsg,&$rMsg) {
        if(!empty($fields['Last__Name'])) {
            return false;
        } else {
        return true;
        }
    }
    ?>


    My Snippet call is
    [!echeckField!]
    [!eForm? &formid=`ContactForm` &subject=`[+subject+]` &to=`[email protected]` &vericode=`1` &ccsender=`1` &tpl=`ContactForm` &report=`ContactFormReport` &invalidClass=`invalidValue` &requiredClass=`requiredValue` &cssStyle=`ContactStyles` &gotoid=`46` &eformOnValidate=`checkField` !]


    contact form chunk is
    <p class="error">[+validationmessage+]</p>
    
    <form method="post" action="[~[*id*]~]" id="ContactForm" name="ContactForm">
    <div class="span-24 clearfix">
    
    <div class="span-12">
    <p>all fields are required</p>
    
                    <p><label for="cfName">your name:</label>
    		<input  name="name" id="cfName"  type="text" eform="Your Name::1:" /></p>
                    
                    <p><label for="cfPhone">phone:</label>
    		<input " name="phone" id="cfPhone"   type="text" eform="Your Phone::0:" /></p>
                    
                   <input style="display: none" type="text" name="Last__Name" id="LastName" size=30 autocomplete="off" eform="LastName::0:" />  
    
                    <p><label for="cfEmail">email:</label>
                    <input  name="email" id="cfEmail"   type="text" eform="Your Email::1:" /></p>
               
                    
                <p><label for="cfDay">your message: </label>
    	    <textarea name="day" id="cfDay" rows="4" cols="20" eform="Your day:textarea:1" ></textarea></p>
    <p>
        Please help us fight spam by entering the CASE SENSITIVE  code below:<br />
        <img src="[+verimageurl+]" alt="verification code" border="1"/>
        </p>
        <p>
        <label accesskey="c" for="vericode">code</label>
        <input type="text" name="vericode" size="20" />
        </p>
    
       		<p><label> </label>
    <input  type="image" id="cfContact" src="assets/images/submit.jpg" alt="Submit Form" value="submit"> </p> </div>
    
    <div class="span-8 push-1 contactBlurb">
     <h4> Get in Touch with us!</h4> 
            <p> We’d love to hear from you<br /></p> <br /><br /><br /></p>
    </div>
    
    		<input  name="formid" type="hidden" value="ContactForm" />
    
    		<input  name="subject" type="hidden" value="Website Contact Form" />
    
    		</div>
    
    </form>


    form lives at http://www.nantuckettriathlonclub.com/contact-us.html When I go there I get this message:
    Fatal error: Cannot redeclare checkfield() (previously declared in /home/acktri/public_html/manager/includes/document.parser.class.inc.php(814) : eval()’d code:2) in /home/acktri/public_html/manager/includes/document.parser.class.inc.php(814) : eval()’d code on line 8

    Any ideas? Any Help is greatly appreciated. I’m using eform 1.4.4.6
      • 26931
      • 2,314 Posts
      maybe just a typo? smiley

      &eformOnValidate=`checkField`

      echeckField
        • 21671
        • 244 Posts
        Hey Sharkbait!

        Thanks for getting back to me.

        I made that change first and got this error message:
        Fatal error: Cannot redeclare checkfield() (previously declared in /home/acktri/public_html/manager/includes/document.parser.class.inc.php(814) : eval()’d code:2) in /home/acktri/public_html/manager/includes/document.parser.class.inc.php(814) : eval()’d code on line 8


        Hmmmm....
          • 26931
          • 2,314 Posts
          does the form work without the function?
            • 21671
            • 244 Posts
            Yes it does.

            -Noah
              • 26931
              • 2,314 Posts
              maybe just a typo? Smiley
              &eformOnValidate=`checkField`
              echeckField
              eh, sorry, the name relates to the function name, not the snippet name
                • 21671
                • 244 Posts
                I’ve changed it back to `checkField` .

                so weird. Identical calls, chunks and snippets work great athttp://www.learnerdesign.com/contact-us.html
                  • 16278
                  • 928 Posts
                  I use this function on a form to check that either a phone number or an email has been supplied - and if neither is present, the error is flagged by a non-empty error message array, rather than returning false:
                  function valext(&$fields,&$vMsg,&$rMsg) {
                  /* Require either phone number or email or both for contact form */
                  	if (empty($fields['cMail']) AND empty($fields['cPhone'])) {
                  		$rMsg[] = '<br />An email address or phone number';
                  	}
                  	return true;
                  }

                  I have a vague recollection that the function always needs to return true, but maybe that’s a false memory. What do you do when the field is populated?

                  smiley KP
                    • 21671
                    • 244 Posts
                    if it is populated, you know that a spammer has filled it in, and the message isn’t submitted.

                    -Noah
                      • 16278
                      • 928 Posts
                      Indeed, that’s what you don’t do. But what do you do? If the function was working, you presumably expect to redisplay the form. You might as well post an error message, in case you have stopped someone with no CSS or something.

                      I tried your code as is, then with the function always returning true and with an error when the trap is populated. I didn’t get the PHP error with the original code, but I didn’t get a form after Submit, either. The amended version worked:
                      <?php
                      function checkField(&$fields,&$vMsg,&$rMsg) {
                          if(!empty($fields['Last__Name'])) {
                          	$rMsg[] = '<br>Unable to send message due to tear in fabric of universe';
                          }
                          return true;
                      }
                      ?>

                      Making the error message a single blank works also, retaining the air of mystery.
                      lipsrsealed KP