SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Noobie - Form Validation

    Well I think I've set up my form validation up ok, but the problem is that when I click on the submit button, I get the necessary alert box pop up listing the fields I need to fill in ... but when I click ok, the form processes anyway.

    How do I stop the form from submitting if there are issues with it?

    Here's the beginning of my form:

    PHP Code:
    <form action='submit.php' method='post' enctype='multipart/form-data' name='submit_form' id='submit' onsubmit='return checkform(this);'
    The function looks like this:

    PHP Code:
    function checkform form )
    {

      
    // ** START **
      
    if (submit_form.postcode.value == "") {
        
    alert"Please enter your postcode." );
        
    form.email.focus();
        return 
    false ;
      }
      
    // ** END **
      
    return true ;

    Any suggestions would be really welcome.

    Thanks,

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code is odd, but the return statements are there, so from what you've shown us it should work fine. Could you provide a link to the page in question?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can I ask you how the code be improved?

    I don't know if it makes any difference, but the Javascript is actually contained in a PHP file.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •