Web Analytics Made Easy -
StatCounter Form Problem - CodingForum

Announcement

Collapse
No announcement yet.

Form Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form Problem

    I have a form im making as part of an assignment at college, however I am having some trouble and im not sure where the error is. There are 4 fields in the form. When its submitted it will error check and display an error message if you forgot to fill something in. My problem is that even if all the fields are filled out then it still takes you to the error message rather than sending the form.

    Here is the HTML form code:

    <html>

    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Contact Form</title>
    </head>

    <body>
    <form action="send.php" name="Contact" method="post">
    <table border="1" style="border-collapse: collapse" width="66%" id="table1" bordercolor="#808080">
    <tr>
    <td colspan="2" bgcolor="#6666FF">
    <p align="center"><b><u><font face="Verdana" size="2" color="#FFFFFF">
    Contact Form</font></u></b></td>
    </tr>
    <tr>
    <td width="13%"><font size="2" face="Verdana">Name:</font></td>
    <td width="85%">&nbsp;<input type="text" name="name" size="33" style="border: 1px solid #C0C0C0"></td>
    </tr>
    <tr>
    <td width="13%"><font size="2" face="Verdana">E-Mail</font></td>
    <td width="85%">&nbsp;<input type="text" name="uemail" size="33" style="border: 1px solid #C0C0C0"></td>
    </tr>
    <tr>
    <td width="13%"><font size="2" face="Verdana">Subject:</font></td>
    <td width="85%">&nbsp;<select size="1" name="subject" style="border: 1px solid #C0C0C0">
    <option selected>Select Subject</option>
    <option value="Comments?">Comments?</option>
    <option value="Misc.?">Misc.?</option>
    <option value="Website Problems?">Website Problems?</option>
    <option value="Questions?">Questions?</option>
    </select></td>
    </tr>
    <tr>
    <td width="13%" valign="top"><font size="2" face="Verdana">Message:</font></td>
    <td width="85%">&nbsp;<textarea rows="12" name="message" cols="46" style="border: 1px solid

    #C0C0C0"></textarea></td>
    </tr>
    <tr>
    <td colspan="2">
    <p align="center">
    <input type="submit" value="Send E-Mail" name="send" style="border: 1px solid #000000">
    <input type="reset" value="Clear Form" name="clear" style="border: 1px solid #000000"></td>
    </tr>
    <tr>
    <td colspan="2" bgcolor="#6666FF">&nbsp;</td>
    </tr>
    </table>
    </form>
    </body>

    </html>




    And here is the PHP Code:

    PHP Code:

    <HTML>
    <HEAD>
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    <center>
    <br>
    <br>
    <br>

    <?php

    $message 
    "Thank you for using my online form.\n";

    // Contact Name

    if ($name)                                     
       {
    $user "Name - $name";            
    $message .= "$user\n";                
       }
     else
       {
    $error .= "You did not enter your name<br>\n";   
       }

    // Email Address

    if ($uemail)                                
       {
    $umail "Email - $uemail";             
    $message .= "$umail\n";                
       }
     else
       {
    $error .= "You did not enter your email address<br>\n";
       }

    // Message Subject

    if ($subject)                                            
       {
    $usubject "Subject - $subject";            
    $message .= "$usubject\n" ;                
       }
     else
       {
    $error .= "You did not select a subject<br>\n";
       }

    // Contact Message

    if ($message)                                
       {
    $comments "Message - $message";             
    $message .= "$comments\n";                
       }
     else
       {
    $error .= "You did not enter any comments<br>\n";
       }

    // If there is no error this part of the code sends the email

    if ($error == "")                                                 
       {                                                                    
    echo 
    "Thank you for using my online form.
    <br>
    <br>You will be emailed a copy of your message.<br><br>
    <br>Please use your browsers back buttom to return to the previous page.
    <br><br>Thank you."
    ;

    // This Part of the code sends the email to the user

    mail("$uemail""Email Challenge"$message"From: Ronnie Williams <[email protected]>");

    // This part of the code sends the email to the owner

    mail("[email protected]""Email Challenge"$message"From: $uemail");
       
    // If there is an error this part of the code displays what the error is

        
    }
      else                                                       
        {                                                         
    print 
    "Sorry, but the form cannot be sent until you correct the following errors:<br>\n";
    print 
    "$error<br>\n";
    print 
    "<br>\n";
    print 
    "<br>\n";
    print 
    "Please use your \"Back\" button to return to the form to correct the omissions. Thank you.<br>\n"
        }
    ?>

    </center>
    </BODY>
    </HTML>

    Any help on what im doing wrong is appreciated..

  • #2
    All the information you are retrieving from the form, you need to convert to

    $_POST['formfieldname']

    so

    $name

    becomes

    $_POST['name'];


    You might also need to change the name of that formfield, to something like full_name, as I think name is a php reserved word

    Comment


    • #3
      sample?

      Can you show me a sample of what you mean with the _Post?


      if ($username)
      {
      $user = "Name - $username";
      $message .= "$user\n";
      }
      else
      {
      $error .= "You did not enter your name<br>\n";
      }

      do you mean

      if ($username)
      {
      $_Post['user'] = "Name - $username";
      $message .= "$user\n";
      }
      else
      {
      $error .= "You did not enter your name<br>\n";
      }

      Comment


      • #4
        Sure

        PHP Code:
        if ($_POST['username'])
        {
        $user "Name - " $_POST['username'];
        $message .= "$user\n";
        }
        else
        {
        $error .= "You did not enter your name<br>\n";

        This is using what is known as SUPER GLOBALS, you should be using these as since php version 4.2.0 register_globals have been turned off, which means basically that the code you're using now will not work. With super globals, these will work whether register_globals are on or off, which helps alot

        More info on super globals here

        http://uk.php.net/manual/en/language...predefined.php
        Last edited by Nightfire; Feb 14, 2004, 08:06 PM.

        Comment


        • #5
          Thanks.. One More thing..

          thanks as that helped my problem. I do have one more thing.. Here are the 2 lines that send the email to the user and the owner:

          mail("$uemail", "Email Challenge", $message, "From: Ronnie Williams <[email protected]>");

          // This part of the code sends the email to the owner

          mail("[email protected]", "Email Challenge", $message, "From: $uemail");

          how do I edit that with the _POST so that the correct email address is shown in the from box? Currently if I send an email it says its from "Apache".. Hope this makes since..

          Comment


          • #6
            Just do the same as I did for the username
            PHP Code:
            mail("[email protected]""Email Challenge"$message"From: $_POST['uemail'] <$_POST['uemail']>"); 

            Comment


            • #7
              thanks

              great thanks.. I was trying to do that but I was leaving out part of the code..

              I fogot to include this part:

              <$_POST['uemail']>

              thanks again

              Comment

              Working...
              X