Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Contact form verification

    Evening Guys, I need some help with verifying my contact form, could anyone point me in the right direction, i want the fields to have words entered in them before the email gets sent.

    Help will be much appreciated - Rob

    Here's what i have currently

    Business End

    <?php


    if(isset($_POST['submit'])) {
    $to = 'myname@myemail.co.uk' ;




    $subject = 'Customer';
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr>
    <tr><td>E-Mail</td><td>".$_POST['email']."</td></tr>
    <tr><td>Moving to</td><td>".$_POST['movingto']."</td></tr>
    <tr><td>Moving from</td><td>".$_POST['movingfrom']."</td></tr>
    <tr><td>Message</td><td>".$_POST['message']."</td>
    </tr></table>" ;
    mail($to, $subject, $message, $headers);
    header('Location: contact.php');


    }
    ?>



    On the contact page itself

    <form name="contact" method="POST" action="process.php" onsubmit="returnfalse">
    <p>&nbsp;</p>
    <p>Contact Form</p>
    <p>&nbsp;</p>

    <table width="220" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td height="28" valign="top">Your name:</td>
    <td><input name="name" type="text"></td>
    </tr>
    <tr>
    <td height="28" valign="top">E-mail address:</td>
    <td><input name="email" type="text"></td>
    </tr>
    <tr>
    <td height="28" valign="top">Message:</td>
    <td><input name="message" type="text" /></td>
    </tr>
    <tr>
    <td height="28" valign="top">Moving To?:</td>
    <td><input name="movingto" type="text" /></td>
    </tr>
    <tr>
    <td height="28" valign="top">Moving From?:</td>
    <td><input name="movingfrom" type="text" /></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td valign="top" align="center"><input type="submit" value="Submit" name="submit" onclick="checkforblank();"></td>
    </tr>
    </table>
    </form>


    As you can see i have tried the very simple check for blank and return false command's

  • #2
    Regular Coder
    Join Date
    Jun 2010
    Location
    Earth
    Posts
    305
    Thanks
    27
    Thanked 2 Times in 2 Posts
    What's wrong with what you have now? Looks like it works
    Last edited by harkly; 03-19-2013 at 09:02 PM.

  • #3
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It works fine but if i spam the submit button it still sends through emails :/

  • #4
    Regular Coder
    Join Date
    Jun 2010
    Location
    Earth
    Posts
    305
    Thanks
    27
    Thanked 2 Times in 2 Posts
    I would validate something say $_POST['email'] that way they have to at least enter something.

    If you want a good one I would set rules that checks to make sure all the required fields have been entered and with valid data.

  • #5
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    And how would i go about that - sorry for being a bit thick proper newbie

  • #6
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    tangoforce will remove your finger nails for using this

    PHP Code:
    if(isset($_POST['submit'])) { 

    build an error array checking all fields you want info in and only send mail if errors = 0

    PHP Code:
    $errors '';
    if (!
    $_POST['email']){ $errors[] = "Email Field is Required. <BR>"}
    if (!
    $_POST['movingto']){ $errors[] = "Moving To is Required. <BR>"}
    if (!
    $_POST['movingfrom']){ $errors[] = "Moving From is Required. <BR>"}
    if (!
    $_POST['message']){ $errors[] = "Message is Required. <BR>"}

    if (
    count($errors == 0)){
    // send mail
    }else{
    // echo errors

    Last edited by Arcticwarrio; 03-19-2013 at 09:22 PM. Reason: removed brackets
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #7
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Really appreciate your post artic however i get 4 syntax errors on the if (!$_POST statments

  • #8
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    sorry missed out all the end of line colons

    PHP Code:

        $errors 
    '';
    if (!
    $_POST['email']){ $errors[] = "Email Field is Required. <BR>";}
    if (!
    $_POST['movingto']){ $errors[] = "Moving To is Required. <BR>";}
    if (!
    $_POST['movingfrom']){ $errors[] = "Moving From is Required. <BR>";}
    if (!
    $_POST['message']){ $errors[] = "Message is Required. <BR>";}

    if (
    count($errors == 0)){
    echo 
    'no errors';// send mail
    }else{
    echo 
    $errors;

    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #9
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I tried to place them on the ends up obs didnt work

  • #10
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I also get a error after i close my php bracket's

    I've tried to look through it but inexperience doesn't help me

  • #11
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    try this instead (tested this time)

    PHP Code:

        $errors 
    '';
    if (!isset(
    $_POST['email'])){ $errors[] = "Email Field is Required. <BR>";}
    if (!isset(
    $_POST['movingto'])){ $errors[] = "Moving To is Required. <BR>";}
    if (!isset(
    $_POST['movingfrom'])){ $errors[] = "Moving From is Required. <BR>";}
    if (!isset(
    $_POST['message'])){ $errors[] = "Message is Required. <BR>";}

    if (
    count($errors) == 0){
    echo 
    'no errors';// send mail
    }else{
    foreach( 
    $errors as $error){
    echo 
    $error;
    }

    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #12
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Still the same

    Where should i place it in my contact form or in the processing page

  • #13
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Retried it and in dreamweaver it didn't have any errors but on my server it gave me this

    Warning: Invalid argument supplied for foreach() in /home/philipma/public_html/process.php on line 11

    Warning: Cannot modify header information - headers already sent by (output started at /home/philipma/public_html/process.php:11) in /home/philipma/public_html/process.php on line 30

    Below are the particular lines

    PHP Code:
    <?php
        $errors 
    '';
    if (!isset(
    $_POST['email'])){ $errors[] = "Email Field is Required. <BR>";}
    if (!isset(
    $_POST['movingto'])){ $errors[] = "Moving To is Required. <BR>";}
    if (!isset(
    $_POST['movingfrom'])){ $errors[] = "Moving From is Required. <BR>";}
    if (!isset(
    $_POST['message'])){ $errors[] = "Message is Required. <BR>";}

    if (
    count($errors) == 0){
    echo 
    'no errors';// send mail
    }else{
    foreach( 
    $errors as $error){  // This one
    echo $error;
    }
    }  


    if(isset(
    $_POST['submit'])) {
       
    $to 'robmarks1994@aol.co.uk' 
       
       
    $subject 'Customer'
       
    $headers  'MIME-Version: 1.0' "\r\n";
       
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
       
    $message "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr>
                   <tr><td>E-Mail</td><td>"
    .$_POST['email']."</td></tr>
                   <tr><td>Moving to</td><td>"
    .$_POST['movingto']."</td></tr>
                   <tr><td>Moving from</td><td>"
    .$_POST['movingfrom']."</td></tr>
                   <tr><td>Message</td><td>"
    .$_POST['message']."</td>
                   </tr></table>" 
    ;
       
    mail($to$subject$message$headers);
       
    header('Location: contact.php'); // This one
      
    }
    ?>

  • #14
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    try:

    PHP Code:

    <?php
    $errors 
    '';
    if (!isset(
    $_POST['email'])){ $errors[] = "Email Field is Required. <BR>";}
    if (!isset(
    $_POST['movingto'])){ $errors[] = "Moving To is Required. <BR>";}
    if (!isset(
    $_POST['movingfrom'])){ $errors[] = "Moving From is Required. <BR>";}
    if (!isset(
    $_POST['message'])){ $errors[] = "Message is Required. <BR>";}

    if (
    count($errors) == 0){
       
    $to 'robmarks1994@aol.co.uk' 
       
       
    $subject 'Customer'
       
    $headers  'MIME-Version: 1.0' "\r\n";
       
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
       
    $message "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr>
                   <tr><td>E-Mail</td><td>"
    .$_POST['email']."</td></tr>
                   <tr><td>Moving to</td><td>"
    .$_POST['movingto']."</td></tr>
                   <tr><td>Moving from</td><td>"
    .$_POST['movingfrom']."</td></tr>
                   <tr><td>Message</td><td>"
    .$_POST['message']."</td>
                   </tr></table>" 
    ;
       
    mail($to$subject$message$headers);
       
    header('Location: contact.php'); // This one
    }else{
    foreach( 
    $errors as $error){  // This one
    echo $error;
    }
    }  
    ?>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #15
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It doesn't seem to do work like it just bypasses the error coding and i still get the same


    Warning: Invalid argument supplied for foreach() in /home/philipma/public_html/process.php on line 23

    Warning: Cannot modify header information - headers already sent by (output started at /home/philipma/public_html/process.php:23) in /home/philipma/public_html/process.php on line 49


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

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