Jump to content


Checking to see if the user filled out the form..


3 replies to this topic

#1 Unreal

    like.. TOTally cool!

  • Members
  • Pip
  • 241 posts

Posted 03 January 2005 - 06:57 AM

Hey,
Well i made a php script, It just gets the users input and sends it to my email. But, i dont no how to make it so when the user doesnt put anything in the textbox's it says "Please fill out the correct forms" BUT i only wnt it to check if certain textbox's are empty.. you no when they like have a * next to them? anyway heres my code..

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Majins PHP script</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana;
	font-size: 9px;
}
-->

input {
font:Verdana;
font-size:9px;
}

.buttons {
 font-family: Verdana;
 font-size: 9px;
 background-color:#999999;
 border:1px;
 border-left-style:solid;
 border-top-style:solid;
 border-bottom-style:solid;
 border-right-style:solid;
 color:#000000;
 margin-right: 6px;
}

.style1 {
	font-size: 9px;
	font-weight: bold;
}
</style></head>

<body>

<?php
// Handle POST method.
if ($_POST)
{
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$country = $_POST['country'];

// Compose simple message
$message = "Someone signed up to a hosting package.<br>Name: $name<br>Email: $email<br>password: $password<br>address: $address<br>City: $city<br>Zip: $zip<br>Country: $country<br>Thanks.";

// This is the email address to send to ( dont mess with the header stuff )
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$email_addr = "kierangill@gmail.com";
$subject = "Hosting Signup!";

// Send message to whoever ( Majin )
mail($email_addr,$subject,$message,$headers);

// Thank the generous user
echo "<h1>Thank you for signing up!</h1>\n";
}
else
{
?>
<form action=majin.php method=POST> 
<table width="430" border="0" cellspacing="0" cellpadding="1">
  <tr>
    <td colspan="2"><strong>Hosting Signup </strong></td>
  </tr>
  <tr>
    <td colspan="2">Please Fill out the following form. </td>
  </tr>
  <tr>
    <td><strong>Name*</strong></td>
    <td><input name="name" type="text" id="name" size="30" maxlength="30" /></td>
  </tr>
  <tr>
    <td><strong>Password*</strong></td>
    <td><input name="password" type="password" id="password" size="30" maxlength="30" /></td>
  </tr>
  <tr>
    <td><strong>Email*</strong></td>
    <td><input name="email" type="text" id="email" size="30" maxlength="30" /></td>
  </tr>
  <tr>
    <td><strong>Address</strong></td>
    <td><input name="address" type="text" id="address" size="30" maxlength="30" /></td>
  </tr>
  <tr>
    <td><strong>City/Town</strong></td>
    <td><input name="city" type="text" id="city" size="30" maxlength="30" /></td>
  </tr>
  <tr>
    <td><strong>Zip/Postcode</strong></td>
    <td><input name="zip" type="text" id="zip" size="30" maxlength="30" /></td>
  </tr>
  <tr>
    <td><strong>Country*</strong></td>
    <td><input name="country" type="text" id="country" size="30" maxlength="30" /></td>
  </tr>
  <tr>
    <td align="left">
      <input name="Submit" type="submit" tabindex="3" value="Register Now" class="buttons" />	</td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
</body>
</html>
<?}?>


#2 adam123

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 2,306 posts
  • Location:London, UK
  • Interests:Programming and stuff.

Posted 03 January 2005 - 01:25 PM

Gimme a second and i'll rewrite the code for you.

#3 adam123

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 2,306 posts
  • Location:London, UK
  • Interests:Programming and stuff.

Posted 03 January 2005 - 01:56 PM

Here you go (Live version: http://sharpknife.net/crap/majin.php):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Majins PHP script</title>
<style type="text/css">
<!--
body,td,th {
font-family: Verdana;
font-size: 9px;
}
-->

input {
font:Verdana;
font-size:9px;
}

.buttons {
font-family: Verdana;
font-size: 9px;
background-color:#999999;
border:1px;
border-left-style:solid;
border-top-style:solid;
border-bottom-style:solid;
border-right-style:solid;
color:#000000;
margin-right: 6px;
}

.style1 {
font-size: 9px;
font-weight: bold;
}
</style></head>

<body>
<?php
if ($_POST)
	{
	$problem = FALSE;

//Remove/Add the if statements for whichever fields aren't neccesary
	
 	 if (empty ($_POST['name']))
  {
 	 $problem = TRUE;
 	 print '<p>Please enter a name!</p>';
  }
  
 	 if (empty ($_POST['email']))
  {
 	 $problem = TRUE;
 	 print '<p>Please enter your e-mail!</p>';
  }
  
 	 if (empty ($_POST['password']))
  {
 	 $problem = TRUE;
 	 print '<p>Please enter a password!</p>';
  }
 
 	 if ($_POST['password'] != $_POST['password2'])
  {
 	 $problem=TRUE;
 	 print '<p>The passwords you entered did not match!</p>';
  }
  
 	 if (empty ($_POST['country']))
  {
 	 $problem=TRUE;
 	 print '<p>Please enter the name of your country.</p>';
  }

 	 if (!$problem)
  {

 	 $name = $_POST['name'];
 	 $email = $_POST['email'];
 	 $password = $_POST['password'];
 	 $address = $_POST['address'];
 	 $city = $_POST['city'];
 	 $zip = $_POST['zip'];
 	 $country = $_POST['country'];

 	 // Compose simple message
 	 $message = "Someone signed up to a hosting package.<br>Name: $name<br>Email: $email<br>password: $password<br>address: $address<br>City: $city<br>Zip: $zip<br>Country: $country<br>Thanks.";

 	 // This is the email address to send to ( dont mess with the header stuff )
 	 $headers  = "MIME-Version: 1.0\r\n";
 	 $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
 	 $email_addr = "kierangill@gmail.com";
 	 $subject = "Hosting Signup!";

 	 mail($email_addr,$subject,$message,$headers);

 	 echo "<h1>Thank you for signing up!</h1>\n";
  }
  else
  {
 	 print '<p>Try again!</p>';
  }
	}
	else
	{
	}
?>

<form action=majin.php method=POST>
<table width="430" border="0" cellspacing="0" cellpadding="1">
 <tr>
   <td colspan="2"><strong>Hosting Signup </strong></td>
 </tr>
 <tr>
   <td colspan="2">Please Fill out the following form. </td>
 </tr>
 <tr>
   <td><strong>Name*</strong></td>
   <td><input name="name" type="text" id="name" size="30" maxlength="30" /></td>
 </tr>
 <tr>
   <td><strong>Password*</strong></td>
   <td><input name="password" type="password" id="password" size="30" maxlength="30" /></td>
 </tr>
 <tr>
 <tr>
   <td><strong>Confirm Password*</strong></td>
   <td><input name="password2" type="password" id="password2" size="30" maxlength="30" /></td>
 </tr>
 <tr>
   <td><strong>Email*</strong></td>
   <td><input name="email" type="text" id="email" size="30" maxlength="30" /></td>
 </tr>
 <tr>
   <td><strong>Address</strong></td>
   <td><input name="address" type="text" id="address" size="30" maxlength="30" /></td>
 </tr>
 <tr>
   <td><strong>City/Town</strong></td>
   <td><input name="city" type="text" id="city" size="30" maxlength="30" /></td>
 </tr>
 <tr>
   <td><strong>Zip/Postcode</strong></td>
   <td><input name="zip" type="text" id="zip" size="30" maxlength="30" /></td>
 </tr>
 <tr>
   <td><strong>Country*</strong></td>
   <td><input name="country" type="text" id="country" size="30" maxlength="30" /></td>
 </tr>
 <tr>
   <td align="left">
     <input name="submit" type="submit" tabindex="3" value="Register Now" class="buttons" /> </td>
   <td>&nbsp;</td>
 </tr>
</table>
</form>
</body>
</html>


#4 Unreal

    like.. TOTally cool!

  • Members
  • Pip
  • 241 posts

Posted 08 January 2005 - 06:27 AM

Thanks Alot. :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users