#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    porterville, ca, usa
    Posts
    2
    Rep Power
    0
    i have the written the script to check for blank form fields (all fields are required)
    on my registration form using :

    if (ereg(".", $first) == 1)
    {
    $verify = "OK";
    }

    else
    {
    print ("<b>ERROR:</b> A first name is required.");

    $verify = "bad";
    }

    my question is, although this script works to verify a form field, it doesnt prevent the incomplete form from being sent to the database. can someone tell me how to stop the form from being sent if it is incomplete, and should this script be included on the form page(html page) or the php page that submits the data to mysql?

    Thanks
    Tim
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    Firstly - try not to use ereg if at all possible, it slows things down (only a smidgen but smidgens grow up) , if you have a form field called 'thisfield' all you need do is check for its existance ie:

    if($thisfield){ echo "OK";} else { etc etc }>

    if you are paranoid you can use if($thisfield!="") instead.

    to stop the database being updated - you just put your DB query after you have done the validation ie:

    if($fieldname){ <? mysql_query....etc ?>} else { error message }.

    Or client side,
    <script>
    function checkit(){
    if(document.formname.fieldname.value==""){
    alert("please enter something");return false;}
    else { return true;}
    }
    </script>

    then in your HTML,
    <form name="formname" onSubmit="return checkit()" method="post' etc >
    <input name="fieldname" type="text etc>

    this will not submit the form unless the field is filled in.

    Wether you validate using PHP or client side using javascript is a personal thing, I prefer clientside cos it avoids several refreshes which can really slow things down

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    porterville, ca, usa
    Posts
    2
    Rep Power
    0
    Thanks, works like a charm!
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    City, State, Country
    Posts
    12
    Rep Power
    0
    For future refrence..I would suggest using...

    Ahh thanks=)
    I was gonna start into that kinda stuff in a few days=)

    ^N|R

    ------------------
    NobodysReal@hotmail.com
    Aim: PRM Magic
    ICQ: 77968493

    [This message has been edited by Nobodys Real (edited August 06, 2000).]

Similar Threads

  1. onClick for buttons to fill form fields
    By scarickhoff in forum HTML Programming
    Replies: 3
    Last Post: February 6th, 2004, 08:03 AM
  2. Referencing (many) form fields in an array
    By z974647 in forum ASP Programming
    Replies: 0
    Last Post: February 3rd, 2004, 11:12 AM
  3. Replies: 2
    Last Post: January 28th, 2004, 07:07 AM
  4. HTTP Error 400: Bad Request, with basic form
    By crackwombat in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 06:40 PM
  5. Checking a form with Javascript
    By Inexactitude in forum JavaScript Development
    Replies: 4
    Last Post: December 21st, 2003, 03:26 PM

IMN logo majestic logo threadwatch logo seochat tools logo