3 Replies Latest reply on Apr 21, 2008 11:51 PM by georgev63

    Form Validation - matching names to initials

      I'm working on a consent form and I would like to have a user enter their initials as verification that they agree (it's more than a checkbox).

      I would like to validate the 2 letter initials to their first/last name.
      I would like to validate this client and server side if possible. I've used the Dynamic form wizard to create my form.

      I have a field for FirstName and LastName.
      I also have a field at the bottom of the form for their initials. How can I compare the user entered initials with the first/last name entered in the form?

      I'm thinking I need to use the Compare Transaction Fields to do this, but I cannot figure out how to get it to validate against the first character of both name fields.

      Any help?
        • 1. Re: Form Validation - matching names to initials
          georgev63 Level 1
          Took me 10 minutes to get this to work properly. First start the custom form wizard, add your 3 fields (firstname, lastname, and initials) and make them all required. Choose regular expression as the validation format for your initials field and in the regular expression textbox enter /\w{2}/. This way it'll only validate when exactly two characters have been entered. Now on to the tricky part. Add a custom BEFORE trigger and enter the following code (minus the line numbers!):
          1. If(tNG.getColumnValue("initials") <> left(tNG.getColumnValue("firstname"),1) & left(tNG.getColumnValue("lastname"),1)) Then
          2. Set update_error = new tNG_error
          3. update_error.init "Initials entered do not match first and last name!", Array(), Array()
          4. Set Trigger_Custom = update_error
          5. else
          6. Set Trigger_Custom = nothing
          7. end if
          8. On Error GoTo 0

          The above code is written in VBScript so you will need to change it if using a different server model.
          • 2. Re: Form Validation - matching names to initials
            Level 1
            I know this makes it very close, but I think I need another whack with the clue stick to make it work.

            I'm using PHP pages with some javascript on my sit.e I believe I have the custom trigger added, but I cann't seem to get past the syntax errors for this code. I also have not been able to translate it correctly to javascript or php. I've tried putting VBSCRIPT types around the code, but I haven't done that correctly either.

            Can you spare another whack to help?
            • 3. Re: Form Validation - matching names to initials
              georgev63 Level 1
              Hi John, try the following code. I'm sure once this is posted, PHP gurus will kindly point out any errors. A custom trigger solution will work best in your scenario since it'll check the form even with Javascript turned off. It'll return a general error message at the top of your form and a field-specific error message right below your initials field.

              This also assumes you have created a form that contains 3 text fields named firstname, lastname, and initials.

              If($tNG->getColumnValue("initials") != LEFT($tNG->getColumnValue("firstname"),1) . LEFT($tNG->getColumnValue("lastname"),1)) {
              $initialsError = new tNG_error("Check your initials!",array(),array());
              ->setFieldError("initials", "Initials entered do not match your first and last name!", array());

              return $initialsError;
              } else {
              return NULL;