njccbeach9
03-13-2010, 09:05 PM
Hi,
I have managed to use PHP and stop PHP from clearing valid fields the user has entered except for two controls. Drop down menus, here is part of my page's code:
if (!filter_var($phone, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^0[1-9][0-9]{8,9}$/")))) {
echo "<p><font color='red'>Please enter a valid UK phone number.</font></p>";
}
if ($employee == "1-10" || $employee == "10-20" || $employee == "20-40" || $employee == "40-80" || $employee == "80-160" || $employee == "160-320" || $employee == "320-640" || $employee == "1000+"){
}else {
echo "<p><font color='red'>Please select the number of employees</font></p>";
}
if($consultingtype == "FinanceSupport" || $consultingtype == "MarketingSupport") {
}else {
echo "<p><font color='red'>Please select a consulting option</font></p>";
}
if (!empty($_POST['message'])) {
} else {
$message = FALSE;
echo "<p><font color='red'>Please enter a message.</font></p>";
}
if(isset($_POST['checkbox'])) {
} else {
echo "<p><font color='red'>You must agree to the Terms and Conditions.</font></p>";
}
}
$osrows = array(
array('idInvalid' => 0, 'label' => 'Please select'),
array('id' => 1, 'label' => '1-10'),
array('id' => 2, 'label' => '20-40'),
array('id' => 3, 'label' => '40-80'),
array('id' => 4, 'label' => '80-160'),
array('id' => 5, 'label' => '160-320'),
array('id' => 6, 'label' => '320-640'),
array('id' => 7, 'label' => '1000+'),
);
?>
</p>
</div>
<table width="508" border="0">
<tr>
<td><p>First name</p></td>
<td><label>
<input type="text" name="Firstname" id="Firstname" value="<?php if (!isset($_POST['submit'])) {} else {
$Firstname=$_POST['Firstname']; echo "$Firstname"; }?>" >
</label> </td>
</tr>
<tr>
<td width="164"><p>Surname</p></td>
<td width="334"><label>
<input type="text" name="Surname" id="Surname" value="<?php if (!isset($_POST['submit'])) {} else {
$Surname=$_POST['Surname']; echo "$Surname"; }?>" >
</label></td>
</tr>
<tr>
<td><p>Email Address</p></td>
<td><label>
<input type="text" name="Email" id="Email" value="<?php if (!isset($_POST['submit'])) {} else {
$Email=$_POST['Email']; echo "$Email"; }?>">
</label></td>
</tr>
<tr>
<td><p>Company name</p></td>
<td><label>
<input type="text" name="Company" id="Company" value="<?php if (!isset($_POST['submit'])) {} else {
$Company=$_POST['Company']; echo "$Company"; }?>">
</label></td>
</tr>
<tr>
<td><p>Telephone Number</p></td>
<td><input type="text" name="Telephone" id="Telephone" value="<?php if (!isset($_POST['submit'])) {} else {
$phone=$_POST['Telephone']; echo "$phone"; }?>"></td>
</tr>
<tr>
<td><p>Number of employees</p></td>
<td><select name="employee" id="employee">
<?php foreach ($osrows as $osrow): ?>
<option value="<?php echo $osrow['id'] ?>"
<?php if ($osrow['id'] == $osrow):?>selected="selected"<?php endif; ?>
><?php echo $osrow['label'] ?></option>
<?php endforeach; ?>
</select>
Feeback and help would be really appreciated...
Thanks
I have managed to use PHP and stop PHP from clearing valid fields the user has entered except for two controls. Drop down menus, here is part of my page's code:
if (!filter_var($phone, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^0[1-9][0-9]{8,9}$/")))) {
echo "<p><font color='red'>Please enter a valid UK phone number.</font></p>";
}
if ($employee == "1-10" || $employee == "10-20" || $employee == "20-40" || $employee == "40-80" || $employee == "80-160" || $employee == "160-320" || $employee == "320-640" || $employee == "1000+"){
}else {
echo "<p><font color='red'>Please select the number of employees</font></p>";
}
if($consultingtype == "FinanceSupport" || $consultingtype == "MarketingSupport") {
}else {
echo "<p><font color='red'>Please select a consulting option</font></p>";
}
if (!empty($_POST['message'])) {
} else {
$message = FALSE;
echo "<p><font color='red'>Please enter a message.</font></p>";
}
if(isset($_POST['checkbox'])) {
} else {
echo "<p><font color='red'>You must agree to the Terms and Conditions.</font></p>";
}
}
$osrows = array(
array('idInvalid' => 0, 'label' => 'Please select'),
array('id' => 1, 'label' => '1-10'),
array('id' => 2, 'label' => '20-40'),
array('id' => 3, 'label' => '40-80'),
array('id' => 4, 'label' => '80-160'),
array('id' => 5, 'label' => '160-320'),
array('id' => 6, 'label' => '320-640'),
array('id' => 7, 'label' => '1000+'),
);
?>
</p>
</div>
<table width="508" border="0">
<tr>
<td><p>First name</p></td>
<td><label>
<input type="text" name="Firstname" id="Firstname" value="<?php if (!isset($_POST['submit'])) {} else {
$Firstname=$_POST['Firstname']; echo "$Firstname"; }?>" >
</label> </td>
</tr>
<tr>
<td width="164"><p>Surname</p></td>
<td width="334"><label>
<input type="text" name="Surname" id="Surname" value="<?php if (!isset($_POST['submit'])) {} else {
$Surname=$_POST['Surname']; echo "$Surname"; }?>" >
</label></td>
</tr>
<tr>
<td><p>Email Address</p></td>
<td><label>
<input type="text" name="Email" id="Email" value="<?php if (!isset($_POST['submit'])) {} else {
$Email=$_POST['Email']; echo "$Email"; }?>">
</label></td>
</tr>
<tr>
<td><p>Company name</p></td>
<td><label>
<input type="text" name="Company" id="Company" value="<?php if (!isset($_POST['submit'])) {} else {
$Company=$_POST['Company']; echo "$Company"; }?>">
</label></td>
</tr>
<tr>
<td><p>Telephone Number</p></td>
<td><input type="text" name="Telephone" id="Telephone" value="<?php if (!isset($_POST['submit'])) {} else {
$phone=$_POST['Telephone']; echo "$phone"; }?>"></td>
</tr>
<tr>
<td><p>Number of employees</p></td>
<td><select name="employee" id="employee">
<?php foreach ($osrows as $osrow): ?>
<option value="<?php echo $osrow['id'] ?>"
<?php if ($osrow['id'] == $osrow):?>selected="selected"<?php endif; ?>
><?php echo $osrow['label'] ?></option>
<?php endforeach; ?>
</select>
Feeback and help would be really appreciated...
Thanks