How to make fields mandatory in web email form

9 replies
Hi,

I have some web mail forms in classic asp, where there are some of the fields that are mandatory. At the moment it will be checked on the next page (after clicking the submit button), by simply checking whether the length of the input was >0. If it's not, an error is displayed.

Isn't there a smarter way to do this, on the first page with the form on? Something so I define whether a field is mandatory or not?
I'm not sure if this can be handled by normal html or classic asp, or whether I should use some kind of Javascript.

The ideal solution could be that if I field is not filled out, it will not submit the form, but write in read below the field, that it should be filled.

I know this can be done, but not how.

Thanks.

Best regards,
Thomas
#email #fields #form #make #mandatory #web
  • Profile picture of the author imarketstuff
    do a search on googly for (form validation with javascript)
    Signature
    I MARKET STUFF

    {{ DiscussionBoard.errors[1876546].message }}
  • Profile picture of the author mywebwork
    This is a job for JavaScript!

    You can use JavaScript to validate your form entries - make sure that mandatory fields are filled in and also verify that entries like e-mail addresses and phone numbers are formatted correctly.

    You can also use JavaScript to disable the Submit button until the mandatory fields are filled in correctly.

    There are literally thousands of samples of this sort of code available, some that incorporate AJAX techniques to give the user a "Web 2.0" experience.

    Bill
    {{ DiscussionBoard.errors[1876642].message }}
  • Profile picture of the author jminkler
    What you want to do is create a validate function in Javascript, and add an onSubmit='validate();' attribute on your form.

    The form:

    HTML Code:
    <form onSubmit='validate();' action="somepage.php" method="post'>
       <input type="text" name="firstName" id="firstName">
    </form>
    The Javascript:

    HTML Code:
    <script>
      /* validate function returns true if "ok" false if "bad" */
      validate = function(){
         /* Check if it is blank */
         if (document.getElementById('firstName').value = ''){
           alert('You must enter a First Name!');
           return false;
         }
         return true;
    
      }
    </script>
    if the onSubmit function returns false .. the form will not submit ...
    {{ DiscussionBoard.errors[1877216].message }}
    • Profile picture of the author jjreview
      Originally Posted by jminkler View Post

      if the onSubmit function returns false .. the form will not submit ...
      Yes, but he wants it BEFORE submission. I believe you want to look into the field events. <input type="text" OnLoseFocus (???) You need to look at the events that go with the input field.

      Put a red asterisk next to required fields and indicate at the bottom that it's a required field. Because most people WANT to be validated. Hahaha, I know I do!
      {{ DiscussionBoard.errors[1886926].message }}
      • Profile picture of the author ThomasTe
        Thanks. Actually I'm thinking about using MS Expression Web. I'll start a separate thread about that probably.

        Best regards,
        Thomas
        {{ DiscussionBoard.errors[1895628].message }}
  • Profile picture of the author lisag
    Originally Posted by ThomasTe View Post

    Hi,

    I have some web mail forms in classic asp, where there are some of the fields that are mandatory. At the moment it will be checked on the next page (after clicking the submit button), by simply checking whether the length of the input was >0. If it's not, an error is displayed.

    Isn't there a smarter way to do this, on the first page with the form on? Something so I define whether a field is mandatory or not?
    I'm not sure if this can be handled by normal html or classic asp, or whether I should use some kind of Javascript.

    The ideal solution could be that if I field is not filled out, it will not submit the form, but write in read below the field, that it should be filled.

    I know this can be done, but not how.

    Thanks.

    Best regards,
    Thomas
    Here's a cool Jquery validation library. Click the Demo link.
    bassistance.de jQuery plugin: Validation
    Signature

    -- Lisa G

    {{ DiscussionBoard.errors[1879510].message }}
  • Profile picture of the author ThomasTe
    Thanks for your input, guys.
    I'll try the code, jminkler.

    Best regards,
    Thomas
    {{ DiscussionBoard.errors[1880828].message }}
  • Profile picture of the author ThomasTe
    If using javascript, is it possible to have it on the page instead of as a popup?

    Best regards,
    Thomas
    {{ DiscussionBoard.errors[1896220].message }}

Trending Topics