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.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Contact form help

    Hey up peeps i have a little question i want to create a simple contact form which atm looks like this:

    Code:
    <form method="post" action="1.php">
    <table>
    <tr>
    <td><label for="fullname">Name:</label></td>
    <td><input type="text" name="fullname" id="fullname" class="txt" /></td>
    </tr>
    <tr>
    <td><label for="email">Email:</label></td>
    <td><input type="text" name="email" id="email" class="txt" /></td>
    </tr>
    <tr>
    <td><label for="emailsubject">Email Subject:</label></td>
    <td><select name="subject">
    	<option>Feedback</option>
    	<option>Other</option>
    	</select></td>
    </tr>
    <tr>
    <td><label for="textarea">Comment:</label></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><textarea name="textarea" rows="3" cols="30"></textarea></td>
    </tr>
    </table>
    <p><input type="submit" name="btnSubmit" id="btnSubmit" value="submit" /></p>
    </form>
    Now i know there is probably something wrong there and i know my 1.php script works to the point of emailing (its not! lol) but what i want and i have seen on 1/2 othersites but i canna remember which is, when it validates it brings up the writing either beside the parts that need to be filled or under etc, etc (the form will get used on anotehr site and be more complecated) but what language is used for that javascript validation and posting?

    Oh one last thing the drop down box i would like that to some how be the selection for the subject when its mailed if you understand what i mean?

    Thanks for any help in advance

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Perhaps this will give you some ideas.
    PHP Code:
    <?php
      
    if(isset($_POST['submit']) && $_POST['submit'] == 'Contact Us'//if form has been submitted
      
    {
        
    //for now:
        
        //get all the data from the form
        
    $replyTo $_POST['email'];
        
    $usersubject $_POST['subject'];
        
    $comments $_POST['comments'];
        
    $from="webmaster@yoursite.com"//this is what will appear in the from part in your email
        
        
    $errors '';
            
        if(
    $replyTo == '')
        {
          
    $error .= "<span class=\"error\">You must enter an <label for=\"email\">e-mail</label> address.</span><br />";
        }
        elseif(!
    eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$"$replyTo)) //if email entered, verify format
        
    {
          
    $error .= "<span class=\"error\">Your <label for=\"email\">email</label> is not of valid format.</span><br />";
        }
        
        if(
    $subject == '')
        {
          
    $error .= "<span class=\"error\">You must enter a <label for\"subject\">subject.</label></span><br />";
        }
        if(
    $comments == '')
        {
          
    $error .= "<span class=\"error\">You must enter something in the <label for\"comments\">comments/questions area.</label></span><br />";
        }
        
        if(
    $error == ''//If no errors
        
    {
          
    $sendTo "you@yoursite.com"//this will be the address that the mail gets sent to
          
    $subject "Web Form: ".$usersubject;
          
          
          
    $body "You have received the following from the web based contact form:\r\n";
          
    $body .= "---------------------------------------------------------------\r\n";
          
    $body .= "Subject:    ".$usersubject."\r\n";
          
    $body .= "From:       ".$replyTo."\r\n";
          
    $body .= "Questions:\r\n";
          
    $body .= $comments ."\r\n";
          
    $body .= "---------------------------------------------------------------\r\n";
          
          
    $headers 'From: '.$from."\r\n" .
                     
    'Reply-To: '.$replyto;     

          if(
    mail($sendTo$subject$body$headers))
          {
            echo 
    "E-mail sucessfully sent. Thank you for contacting us.";
          }
          else
          {
            
    $error "<span class=\"error\">Unfortunately, we were unable to send your e-mail. Please try again.</span>";
            exit();
          }
        }
      }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charet=iso-8859-1" />
    <title>Mail Form</title>
    <style type="text/css">
    div.error {
    display:block;
    clear:both;
    background:#CCCCCC;
    border:1px solid #000;
    }
    div.error label {
    font-weight:bold;
    border:0;
    display:inline;
    }
    span.error {
    border:0;
    }
    form label {
    width:150px;
    float:left;
    }
    label, input {
    margin:3px 0;
    }
    </style>
    </head>
    <body>
         
               <?php
              
    if(!empty($error))
              {
                echo 
    "<div class=\"error\">\n";
                echo 
    "<h4>Uh oh! An error occurred...</h4>";
                echo 
    $error;
                echo 
    "</div>\n";
              }
            
    ?>
                <form method="post" action="<?php echo $_SERVER['PHP_SELF'?>">
              <label for="email">Your Email</label>
              <input type="text" name="email" id="email" value="<?php echo $replyTo?>" size="25" /><br />
              <label for="subject">Subject</label>
              <input type="text" name="subject" id="subject" value="<?php echo $subject?>" size="25" /><br />
              <label for="comments">Your comments and/or questions:</label>
                <textarea name="comments" id="comments" rows="8" cols="25"></textarea><br />
              <input type="submit"name="submit" value="Contact Us" />
                </form>
    </body>
    </html>

  • #3
    New Coder
    Join Date
    Nov 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok cool and thanks i'll give it ago now its only 2am lol

    oh and _Aerospace_Eng_ you need a promotion on this site i think your always about and always help lol

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    The Netherlands, Baarn, Ut.
    Posts
    4,252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Helpful member, anyone?

    I totally agree, and you can voice your opinion here: http://www.codingforums.com/showthread.php?t=71444?
    Regards,
    Ronald.
    ronaldvanderwijden.com


  •  

    Posting Permissions

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