Hi, I'm a PHP newbie, hosting a site on godaddy. I am attempting to create a form (with some text boxes with validation) that will be filled out by users that will be sent to my email account. I'm forced to use godaddy's form mailer but I'm having trouble including any validation. I can get it to work without my validation but I really need some sort of validation. Please see my code below, any help would be great!

Code for index.html

<!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" xml:lang="en" lang="en">

<head>
<title>Book your party with us!</title>
</head>
<body>
<div>Book your party with us!!!</div>
<table>

<tr>
          <td width="480" class="bodyText"><!-- InstanceBeginEditable name="PageContent" -->

            <p><span class="style2">Complete this form with as much information as you can. We'll be back in touch within 2 hours with a quote.</span></p>
            
            <form action="/sendmail.php" method="post">
	    <input type="hidden" name="subject" value="Submission" /> 
	    <input type="hidden" name="redirect" value="gdform.php" />
		
            <span class="subHeader">Contact information:</span>

            <table border="0" cellpadding="5" cellspacing="1">

              <tr>

                <td colspan="2"><div width="99"</div><div align="right">contact name (ex. First Name, Last Name)</div></td>

                <td width="138"><input type="text" name="firstname" value="" size="16" tabindex="1" /></td>

                <td width="205"><div align="right">

                  <input type="text" name="lastname" value="" size="25" tabindex="2" />

                </div></td>

              </tr>

              <tr>

                <td><div align="left">telephone (ex.555-555-5555)</div></td>

                <td><input type="text" name="telephone" value="" size="18" tabindex="3" /></td>

                <td><div align="right">best time to call:  

                    <select name="callTime" tabindex="4">

                      <option selected="selected">morning</option>

                      <option>noon</option>

                      <option>afternoon</option>

                      <option>evening</option>

                    </select>

                </div></td>

              </tr>

              <tr>

                <td><div align="right">email address</div></td>

                <td colspan="2"><div align="right">

                  <input type="text" name="email" value="" size="52" tabindex="5" />

                </div></td>

              </tr>

              <tr>

                <td colspan="3"><span class="subHeader">About your event:</span></td>

              </tr>

              <tr>

                <td colspan="1"><div align="right">number of guests:</div></td>

                <td colspan="3"><select name="numGuests" tabindex="6">

                  <option>less than 25</option>

                  <option selected="selected">25 to 50</option>

                  <option>51 to 75</option>

                  <option>76 to 100</option>

                  <option>101 to 125</option>

                  <option>126 to 150</option>

                  <option>151 to 175</option>

                  <option>176 to 200</option>

                  <option>201 to 225</option>

                  <option>226 to 250</option>

                  <option>251 to 275</option>

                  <option>276 to 300</option>

                  <option>more than 300</option>

                </select></td>

              </tr>

              <tr>

                <td><div align="right">event type:</div></td>

                <td colspan="2"><select name="event" tabindex="7">

                  <option>private house party</option>

                  <option>birthday party</option>

                  <option>wedding</option>

                  <option>corporate event</option>

                  <option>bachelor/ette party</option>

                  <option selected="selected">holiday party</option>

                  <option>other</option>

                </select></td>

              </tr>

              <tr>

                <td><div align="right">type of bar:</div></td>

                <td colspan="2"><select name="barType" tabindex="8">

                  <option selected="selected">full liquor</option>

                  <option>specialty drink</option>

                  <option>beer &amp; wine</option>

                  <option>non-alcoholic</option>

                  <option>custom tailored</option>

                </select></td>

              </tr>

              <tr>

                <td><div align="right">event date and time:(ex. mm/dd/yyyy 00:00pm)</div></td>

                <td><input type="text" name="eventDate" value="" size="23" tabindex="9" /></td>

                <td><div align="right">length::

                    <select name="length" tabindex="10">

                    <option>2 hours</option>

                    <option>3 hours</option>

                    <option selected="selected">4 hours</option>

                    <option>5 hours</option>

                    <option>6 hours</option>

                    <option>7 hours</option>

                    <option>8 hours</option>

                    <option>more than 8 hours</option>

                    </select>

                </div></td>

              </tr>

              <tr>

                <td><div align="right">venue contact info (name/address/phone/etc.)</div></td>

                <td colspan="2"><div align="right">

                  <input type="text" size="55" tabindex="12" value="" name="eventDesc" label="Contact Info" />

                </div></td>

              </tr>

              <tr>

                <td colspan="3"><span class="subHeader">Special requirements:</span></td>

              </tr>

              <tr>

                <td colspan="2"><input type="checkbox" name="specialRequest1" value="glassware rental" />

glassware rental </td>

                <td><input type="checkbox" name="specialRequest2" value="portable bar rental" />

portable bar rental</td>

              </tr>

              <tr>

                <td colspan="2"><input type="checkbox" name="specialRequest8" value="cooler rental" />

                tables and chairs </td>

                <td><input type="checkbox" name="specialRequest4" value="tables and chairs" />

other rentals/sales. </td>

              </tr>

              <tr>

                <td><input type="checkbox" name="specialRequest5" value="costumes" />

costumes </td>

                <td><input type="checkbox" name="specialRequest4" value="decorations" />

food catering</td>

                <td><input type="checkbox" name="specialRequest5" value="cocktail server" />

cocktail server(s) </td>

              </tr>

              <tr>

                <td><input type="checkbox" name="specialRequest11" value="security" />

security </td>

                <td><input type="checkbox" name="specialRequest13" value="valet" />

                  ice sculptures/luges</td>

                <td> <input type="checkbox" name="specialRequest12" value="photography-video" />

                cigar rolling</td>

              </tr>

              <tr>

                <td><input type="checkbox" name="specialRequest10" value="entertainment" />

entertainers (deejays, musicians, dancers, performers)</td>

                <td colspan="2">

                  <div align="right">

                    <input type="text" size="52" name="entNeeds" value="" />

                  </div></td>

              </tr>

              <tr>

                <td><input type="checkbox" name="specialRequest7" value="Other Special Request" />

other: (describe any other requests)</td>

                <td colspan="2"><div align="right">

                  <input type="text" size="52" name="otherNeeds" value="" />

                </div></td>

              </tr>

              <tr>

                <td colspan="3"><span class="subHeader">Additional Information/Comments:</span> </td>

              </tr>

              <tr>

                <td>&nbsp;</td>

                <td colspan="2"><div align="right">

                  <textarea cols="40" name="comments"></textarea>

                </div></td>

              </tr>

              <tr>

                <td>&nbsp;</td>

                <td colspan="2"><div align="right">

                  <input type="reset" value="clear form" />

                  <input type="submit" value="request info/quote" />

                </div></td>

              </tr>

            </table>


</form>

</body>
</html>

Code for php file

<?php
  $firstname = $_REQUEST['firstname'];
  $lastname = $_REQUEST['lastname'];
  $email = $_REQUEST['email'] ;
  $comments = $_REQUEST['comments'] ;

 
  if (!isset($_REQUEST['email'])) {
    header( "Location: http://www.b-royaldesigns.com/feedback/" );
  }
  elseif (empty($firstname) || empty($lastname) || empty($email) || empty($comments)) {
    header( "Location: http://www.b-royaldesigns.com/error.html" );
  }
  else {
    mail( "contact@b-royaldesigns.com", "Feedback Form Results",
      $firstname,$lastname,$comments, "From: $email" );
    header( "Location: http://www.b-royaldesigns.com/thankyou.html" );
  }

?>

Recommended Answers

All 5 Replies

Please define 'validation'? :D

When I say "validation", I mean I want to validate certain text boxes that are filled out properly. If a person leaves a certain text box blank, I want a message to appear (error.html) that you left it blank and you need to fill it out before the email can be sent to the webmaster. Does that make sense?

Yes and as I skimmed that is what you're doing already?

sorry, i forgot to include the part that is giving me problems. Please see below. I've been playing around with where to put this code. Whether in the index.html or my sendmail.php file (since that's where the validation is). It either validates and won't send the email or it sends the email with no validation (no matter what fields are filled out). Any help would be appreciated.

<form action="/gdform.php" method="post">
</form>

the above is the godaddy formmailer that you have to include when hosting on their site....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.