Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Forms help

  • 27-05-2000 04: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