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

    In my eForm template i’ve this:

    <p>
    <strong>I Agree</strong><input type="radio" name="privacyon" value="si" eform="Agree::1" />
    <strong>I do not agree</strong><input type="radio" name="privacyon" value="no" />
    </p>

    I need that on validation eForm checks to see if I Agree is selected, if not or if I do not agree is selected returns an error.

    Is it possible using only eForms?
      • 24719
      • 194 Posts
      use the eform event &eFormOnValidate. from the docs:


      &eFormOnValidate
      Expects a function name. This function will be called directly after the form validation has taken place. You can use this event to add your own extra validation logic. The function should accomodate the following parameters

      * &$fields - (as reference) an associative array of field and placeholder values.
      * &$vMsg - (as reference) a numeric array of validation error messages.
      * &$rMsg - (as Reference) a numeric array of missing required fields.


      You can create a little function that checks to make sure that ’I Agree’ is selected, or if not, put a message in the $vMsg array. Then eform will return the form with the error message inserted into the placeholder [+validationmessage+]
        • 25868
        • 9 Posts
        Ok thanks, but there is no documentation on that kind of function, and i’m not expert in php. Have you got a link with some docs on that function?
          • 24719
          • 194 Posts
          if you download eform from the repository, there are some examples in there.

          you need to do 3 things to do this though:

          1) define a function that takes the 3 parameters given above, and save it as a snippet (e.g. handleForm):

          function handleForm(&$fields, &$vMsg, &$rMsg)
          {
          if ($fields['privacyon'] != 'si')
          {
            $vMsg[] = "You must agree to continue";
          }
          }
          


          2) On the page you are using eForm on, insert a call to this snippet before eForm:
          [[handleForm]]


          3) Add an extra parameter to the eform call:
          [!eForm .... &eFormOnValidate=`handleForm`!]


          maybe you can do all of this using an eform attribute in your input tag like the one you’ve got. i find it get ’s a bit difficult with radio buttons and checkboxes though