Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP Contact – does not validate form in Oprea & Chrome

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #28614
    ponyack
    Participant

    Hi,

    I was using the PHP contact form that I download from CSS Tricks. When the user clicks submit in Opera or Chrome it submits the form even if the text fields are blank –

    Any help with this would be appreciated

    John

    #73390
    Irrorate
    Member

    To make sure all the fields have a value, you’d need to run something like:

    Code:
    if(empty($_POST[‘name’]) || empty($_POST[’email’]) || empty($_POST[‘comments’])){
    //run code here
    die()
    } else {
    //continue with validation
    }

    That basically says "if a field is empty, run code & die (stop processing), else continue with validation"

    #73536
    ponyack
    Participant

    Hi,

    Thanks for the relpy. That makes sense but I am not so versed with PHP, so I am not sure how to get the code to work. Could you help me with getting the validation to work?

    Below is the code that I am using right now

    John

    Code:
    “);

    // redirect to success page
    // CHANGE THE URL BELOW TO YOUR “THANK YOU” PAGE
    if ($success){
    print ““;
    }
    else{
    print ““;
    }
    ?>

    #73560
    Irrorate
    Member
    Code:
    $value){
    if(empty($value)){
    echo “You have left the ” . $key . ” field blank.”;
    die();
    }
    }

    // send email
    $success = mail($EmailTo, $Subject, $Body, “From: <$EmailFrom>“);

    // redirect to success page
    // CHANGE THE URL BELOW TO YOUR “THANK YOU” PAGE
    if ($success){
    print ““;
    }
    else{
    print ““;
    }
    ?>

    That should work. It is untested, but try it and get back to me.

    #73569
    ponyack
    Participant

    Hi,

    That works great.

    I just realized that the PHP form has a bunch of JavaScript that is supposed to do the validation.

    This is a link – its the second form https://css-tricks.com/downloads/php-stuff/

    Anyway – thanks for the help – if you have time, I have a style quesiton – When the warning happens is there a way to create that on the same page or at least a pop up –

    John

    #73324
    Irrorate
    Member
    "ponyack" wrote:
    Hi,

    That works great.

    I just realized that the PHP form has a bunch of JavaScript that is supposed to do the validation.

    This is a link – its the second form https://css-tricks.com/downloads/php-stuff/

    Anyway – thanks for the help – if you have time, I have a style quesiton – When the warning happens is there a way to create that on the same page or at least a pop up –

    John

    Hey ponyack,

    You would either have to use JavaScript to validate the fields (but if JS is disabled, that will fail) or you’re going to have to use AJAX to check for the PHP reply and show it on the screen. Both of which I don’t have much experience in :p

    #73680
    ponyack
    Participant

    Hi,

    Thanks for the help, I have found another PHP script that does a good job of validation.

    John

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Back End’ is closed to new topics and replies.