Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Forms help

Options
  • 27-05-2000 5:32pm
    #1
    Closed Accounts Posts: 1,484 ✭✭✭


    Right, how do I make a form so that when certain fields aren't filled it will bring you back with all the stuff you put in still there but with a message saying "YOU FORGET TO FILL OUT XXXXX FIELD!"


Comments

  • Closed Accounts Posts: 6,601 ✭✭✭Kali


    use javascript or server side scripts to check to see if the form variables are valid.


  • Closed Accounts Posts: 202 ✭✭Karla


    The easiest way would be javascript. Just test each field to see if it's empty and pop up an alert box if it is.
    Something like this: (formatting will be ****ered)

    function validate_form() {

    if (document.form.value1 = "") {
    alert("You have to fill in value1");
    }

    }

    Of course if you're using a CGI script you can do it a much nicer way, just generate a page with the form fields that they haven't filled in and use hidden values to fill the fields they have filled in.



  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Using a validation script like the one above is a good idea, but you should always check server side as well for browsers without js, or with js turned off, and also to avoid hassle from people deliberately sending bad data maliciously.


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    oh, and the client side thing should return false if it does an alert, to stop it submitting the form until it is ready. E.g.

    <script type="text/javascript">
    <!--
    function validateForm() {
    if (document.form.value1 = "") {
    alert("You have to fill in value1");
    return false
    }
    else return true
    }
    -->
    </script>
    .
    .
    .
    <form action="blah.blah"
    onsubmit="return(validateForm())">
    .
    .
    .


Advertisement