PHP FORM HELP!!!
Posted: Sat Apr 03, 2004 9:50 pm
I'm going to let you all know right off hand that I have practically no experience with php, and that I'm stuck working on this script because our programmer is off for a couple weeks. I tried adding the "required fields" snippets of code, but when I submit the form it lists all the errors.
Example:
Your form had the following errors : Sorry, you must enter a name.
Sorry, you must enter your email address.
Sorry, you must enter your experience.
Sorry, you must advise wether your a client of ours or not.
Sorry, you must advise wether you have been employed with us or not.
Sorry, you must advise how you wish to be paid.
Sorry, you must advise how you plan on selling.
Sorry, you must advise wether you have operated or been employed by another web hosting company or not.
Please go back and try again.
Here is the code
Now I know my "variables" are a little long, but I need it that way for specific reasons. .....What am I doing wrong?
Example:
Your form had the following errors : Sorry, you must enter a name.
Sorry, you must enter your email address.
Sorry, you must enter your experience.
Sorry, you must advise wether your a client of ours or not.
Sorry, you must advise wether you have been employed with us or not.
Sorry, you must advise how you wish to be paid.
Sorry, you must advise how you plan on selling.
Sorry, you must advise wether you have operated or been employed by another web hosting company or not.
Please go back and try again.
Here is the code
Code: Select all
<?php
error_reporting(E_ALL);
if ($_SERVER['REQUEST_METHOD'] == "POST")
{ extract($_POST); } else { extract($_GET); }
/* extract() takes the name=" " of your form fields and makes them into variables. So if you had <input type="text" name="fname"> -- you now have a variable called $fname that holds the value (if any) that the user entered into that text box.
After this step, you can add your custom checking routines (what fields are required, etc.) Here I'm working with a simple form, that must have name city*/
$Full_Name = isset($Full_Name) ? $Full_Name : NULL;
$Email_Address = isset($Email_Address) ? $Email_Address : NULL;
$Experience = isset($Experience) ? $Experience : NULL;
$CPQIS_Client = isset($CPQIS_Client) ? $CPQIS_Client : NULL;
$Employed_by_CPQIS = isset($Employed_by_CPQIS) ? $Employed_by_CPQIS : NULL;
$How_do_you_wish_to_be_payed = isset($How_do_you_wish_to_be_payed) ? $How_do_you_wish_to_be_payed : NULL;
$How_do_you_plan_on_selling = isset($How_do_you_plan_on_selling) ? $How_do_you_plan_on_selling : NULL;
$Have_you_ever_operated_or_been_employed_by_another_web_hosting_company = isset($Have_you_ever_operated_or_been_employed_by_another_web_hosting_company) ? $Have_you_ever_operated_or_been_employed_by_another_web_hosting_company : NULL;
$errors = ""; //holds any errors
if ($Full_Name == NULL)
{
$errors .= "Sorry, you must enter a name.<br />";
}
if ($Email_Address == NULL)
{
$errors .= "Sorry, you must enter your email address.<br />";
}
if ($Experience == NULL)
{
$errors .= "Sorry, you must enter your experience.<br />";
}
if ($CPQIS_Client == NULL)
{
$errors .= "Sorry, you must advise wether your a client of ours or not.<br />";
}
if ($Employed_by_CPQIS == NULL)
{
$errors .= "Sorry, you must advise wether you have been employed with us or not.<br />";
}
if ($How_do_you_wish_to_be_payed == NULL)
{
$errors .= "Sorry, you must advise how you wish to be paid.<br />";
}
if ($How_do_you_plan_on_selling == NULL)
{
$errors .= "Sorry, you must advise how you plan on selling.<br />";
}
if ($Have_you_ever_operated_or_been_employed_by_another_web_hosting_company == NULL)
{
$errors .= "Sorry, you must advise wether you have operated or been employed by another web hosting company or not.<br />";
}
if ($errors != "")
{
echo "Your form had the following errors : ";
echo $errors;
echo "Please go back and try again.";
die();
}
$subject = "Free Ded. Server Contest Signup " . $_POST['Email Address'];
$message = "Information Posted:\n\n Full Name: " . $_POST['Full_Name'] . "\nEmail Address: " . $_POST['Email_Address'] . "\nExperience: " . $_POST['Experience'] . "\nHTML: " . $_POST['HTML'] . "\nPHP: " . $_POST['PHP'] . "\nPERL: " . $_POST['PERL'] . "\nNone: " . $_POST['None'] . "\nCPQIS Client?: " . $_POST['CPQIS_Client'] . "\nClient ID: " . $_POST['Client_ID'] . "\nEmployed by CPQIS?: " . $_POST['Employed_by_CPQIS'] . "\nPosition: " . $_POST['Position'] . "\nWebsite: " . $_POST['Website'] . "\nHow do you wish to be payed?: " . $_POST['How_do_you_wish_to_be_payed'] . "\nMailing Addy: " . $_POST['Mailing_Addy'] . "\nPayPal Addy: " . $_POST['PayPal_Addy'] . "\nHow do you plan on selling?: " . $_POST['How_do_you_plan_on_selling'] . "\nHave you ever operated or been employed by another web hosting company?: " . $_POST['Have_you_ever_operated_or_been_employed_by_another_web_hosting_company'] . "\nCompany URL: " . $_POST['Company_URL'] . "\nComments: " . $_POST['Comments'];
mail ("coryp@cpqservices.com", $subject, $message);
?>
<span class="style11">Thank you for your registration. We will get back to you as soon as we review your application. </span></span>
</p>
<form method="POST" action="<?php echo $PHP_SELF; ?>">
<p align="center" class="style7 style14">Your Information</p>
<div align="center" class="style15">
<table width="44%" border="2" cellspacing="0" cellpadding="1">
<tr>
<td width="259"><div align="left"><span class="style13"><span class="style9">*</span><span class="style3">Full Name</span></span></div></td>
<td width="259"><input name="Full Name" type="text" id="Full Name"></td>
</tr>
<tr>
<td><div align="left"><span class="style9">*</span><span class="style13">Email Address </span></div></td>
<td><input name="Email Address" type="text" id="Email Address"></td>
</tr>
<tr>
<td><div align="left"><span class="style9">*</span><span class="style13">Experience</span></div></td>
<td> <textarea name="Experience" id="Experience">I have experience in...</textarea></td>
</tr>
<tr>
<td><div align="left"><span class="style9">*</span><span class="style13">I am familiar with </span></div></td>
<td><input name="HTML" type="checkbox" id="HTML" value="checkbox">
HTML
<input name="PHP" type="checkbox" id="PHP" value="checkbox">
PHP
<input name="PERL" type="checkbox" id="PERL" value="checkbox">
PERL
<input name="None" type="checkbox" id="None" value="checkbox">
None</td>
</tr>
<tr>
<td><div align="left"><span class="style3"><span class="style13"><span class="style9">*</span>Are you a CPQIS client? </span></span></div></td>
<td> <select name="CPQIS Client" id="CPQIS Client">
<option>Yes</option>
<option>No</option>
</select>
If yes <input name="Client ID" type="text" id="Client ID" value="Client ID" size="15">
<span class="style17"><a href="javascript:popUp()">-What's this?</a></span> </td>
</tr>
<tr>
<td><div align="left"><span class="style9">*</span><span class="style13">Are you or have you been employed by CPQIS? </span></div></td>
<td><select name="Employed by CPQIS" id="Employed by CPQIS">
<option>Yes</option>
<option>No</option>
</select>
If yes
<input name="Position" type="text" id="Position" value="Position"></td>
</tr>
<tr>
<td><div align="left" class="style3"><strong>Website</strong></div></td>
<td><input name="Website" type="text" id="Website" value="http://"></td>
</tr>
</table>
<p class="style3"><strong>Payment Options</strong></p>
<table width="44%" border="2" cellpadding="1" cellspacing="0">
<tr>
<td width="259"><div align="left"><span class="style13"><span class="style9">*</span><span class="style3">How do you wish to be payed for orders over the required? </span></span></div></td>
<td width="259"><p>
<select name="How do you wish to be payed" id="How do you wish to be payed">
<option>PayPal</option>
<option>Mail</option>
</select>
<span class="style3">NOTE: You will be payed quarterly commissions for each order over the required. </span></p>
</td>
</tr>
<tr>
<td><div align="left"><span class="style13">Mailing Address </span></div></td>
<td><textarea name="Mailing Addy" id="Mailing Addy"></textarea></td>
</tr>
<tr>
<td><div align="left"><span class="style13">PayPal Address </span></div></td>
<td> <input name="PayPal Addy" type="text" id="PayPal Addy"></td>
</tr>
</table>
<p class="style3"><strong>Other</strong></p>
<table width="44%" border="2" cellpadding="1" cellspacing="0">
<tr>
<td width="259"><div align="left"><span class="style13"><span class="style9">*</span><span class="style3">How do you plan on selling? </span></span></div></td>
<td width="259"><p>
<textarea name="How do you plan on selling" id="How do you plan on selling"></textarea>
</p></td>
</tr>
<tr>
<td><div align="left"><span class="style9">*</span><span class="style13">Have you ever operated or been employed by another web hosting company? </span></div></td>
<td><select name="Have you ever operated or been employed by another web hosting company" id="Have you ever operated or been employed by another web hosting company">
<option>Yes</option>
<option>No</option>
</select>
If yes
<input name="Company URL" type="text" id="Company URL" value="Company URL" size="15"></td>
</tr>
<tr>
<td><div align="left" class="style3"><strong>Comments</strong></div></td>
<td> <textarea name="Comments" id="Comments"></textarea></td>
</tr>
</table>
</div>
<p align="center">
<span class="style12">
<input type="submit" value="SIGNUP!" />
</span> </p>
</form>
<?
if (!mail($Full_Name,$Email_Address,$Experience,$CPQIS_Client,$Employed_by_CPQIS,$How_do_you_wish_to_be_payed,$How_do_you_plan_on_selling,$Have_you_ever_operated_or_been_employed_by_another_web_hosting_company))
{
die("There was an error sending your email");
}
?>