Jump to content

from help


wright67uk

Recommended Posts

<form  name="add" action="#" method="post"><fieldset><legend>Add Your Business</legend>

<p><label for="Name">Name</label><input type="text" name="Name" id="Name" maxlength="50" value="
<?php  $Name = $_POST['Name'];  if (!empty($Name)) echo $Name; ?>"/></p>

<p><label for="Phone">Phone</label> <input type="text" name="Phone" id="Phone" maxlength="50" value="
<?php $Phone = $_POST['Phone']; if (!empty($Phone)) echo $Phone; ?>"/></p>

<p><label for="Email">Email</label><input type="text" name="Email" 	id="Email"	maxlength="50" value="
<?php $Email = $_POST['Email']; if (!empty($Email)) echo $Email; ?>" /></p>

<p><label for="Postcode">Postcode</label><input type="text" name="Postcode" id="Postcode" maxlength="50" value="
<?php $Postcode = $_POST['Postcode']; if (!empty($Postcode)) echo $Postcode; ?>"/></p>

<p><label for="Web Address">Web Address</label><input type="text" name="Website" id="Website" maxlength="50" value="
<?php $Website = $_POST['Website']; if (!empty($Website)) echo $Website; ?>"/></p>

<select name="drop_1" id="drop_1"> 
<option value="" selected="selected" disabled="disabled">Select a Category</option>  
<?php getTierOne(); ?>

</select> 
<span id="wait_1" style="display: none;"><img alt="Please Wait" src="ajax-loader.gif"/></span>
<span id="result_1" style="display: none;"></span><br />
</fieldset></form>
<div id="results">

<?php 
function checkPostcode (&$toCheck) 
{ 
$alpha1 = "[abcdefghijklmnoprstuwyz]";                           
$alpha2 = "[abcdefghklmnopqrstuvwxy]";                          
$alpha3 = "[abcdefghjkstuw]";                                   
$alpha4 = "[abehmnprvwxy]";                                       
$alpha5 = "[abdefghjlnpqrstuwxyz]";                               
$pcexp[0] = '^('.$alpha1.'{1}'.$alpha2.'{0,1}[0-9]{1,2})([0-9]{1}'.$alpha5.'{2})$';  
$pcexp[1] =  '^('.$alpha1.'{1}[0-9]{1}'.$alpha3.'{1})([0-9]{1}'.$alpha5.'{2})$';
$pcexp[2] =  '^('.$alpha1.'{1}'.$alpha2.'[0-9]{1}'.$alpha4.')([0-9]{1}'.$alpha5.'{2})$';
$pcexp[3] =  '^(gir)(0aa)$';  
$pcexp[4] = '^(bfpo)([0-9]{1,4})$';
$pcexp[5] = '^(bfpo)(c\/o[0-9]{1,3})$'; 
$Postcode = strtolower($toCheck);
$Postcode = str_replace (' ', '', $Postcode);
$valid = false;
foreach ($pcexp as $regexp) {    
if (ereg($regexp,$Postcode, $matches)) {      
$toCheck = strtoupper ($matches[1] . ' ' . $matches [2]);    
$toCheck = ereg_replace ('C\/O', 'c/o ', $toCheck);
$valid = true;
break;     
}  
}  
if ($valid){return true;} else {return false;};
}



if(isset($_POST['submit']))
{
$drop = mysql_real_escape_string($_POST['drop_1']);
$tier_two = mysql_real_escape_string($_POST['Subtype']);
$Name = mysql_real_escape_string($_POST["Name"]);
$Phone = mysql_real_escape_string($_POST["Phone"]);
$Email = mysql_real_escape_string($_POST["Email"]);
$Postcode = mysql_real_escape_string($_POST["Postcode"]);
$Website = mysql_real_escape_string($_POST["Website"]);
if($Name == '')
{

/*
foreach ($_POST as $key => $value) { 
    $_POST[$key] = mysql_real_escape_string($value); 
  } 
*/

die ("<div class=\"form\">You did not complete the name field, please try again</div>");
}
elseif  ($Phone == '' or (preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $Phone)))
{	
	die("<div class=\"form\"> You completed the telephone field incorrectly, please try again</div>");
}		
elseif  ($Email == '' or (!filter_var($Email, FILTER_VALIDATE_EMAIL)))
{
	die("<div class=\"form\"> You completed the Email field incorrectly, please try again</div>");
}									   
elseif  ($Postcode == '' or (!checkPostcode($Postcode)))
{
	die("<div class=\"form\"> You did not complete the Postcode field correctly, please try again</div>");
}		  
elseif  ($Website == '' or (!preg_match("~^[a-z0-9.-]+\.(com|org|net|edu|co.uk)~i", $Website))) //add tickbox here
{   																									
	die("<div class=\"form\">You completed the website field incorrectly, please try again</div>");
}
else
{
	echo("<div id=\"formtwo\">Thankyou for submiting your details, you will be added to our directory shortly</div>");
}
$query = ("INSERT INTO business (`id`, `Name`,  `Type`, `Subtype`, `Phone`, `Email`, `Postcode`, `WebAddress`, `confirmed`)
		  VALUES ('NULL', '$Name', '$drop', '$tier_two' , '$Phone', '$Email', '$Postcode', '$Website', 'Yes')");
mysql_query($query) or die ( "<br>Query: $query<br>Error: " .mysql_error());
}
?>

Link to comment
https://forums.phpfreaks.com/topic/237466-from-help/
Share on other sites

Apologies as I didint mean to submit just yet.

 

I'd like to add a checkbox into my form below, for any customers that don't have websites.

Im not sure of the best way to do this or the correct syntax.

 

Maybe somthing like;

 

<p><label for="Web Address">Web Address</label><input type="text" name="Website" id="Website" maxlength="50" value="
<?php $Website = $_POST['Website']; if (!empty($Website)) echo $Website; ?>"/></p>
<p>If you dont have a website please click here</p><input type="checkbox" name="website" value="true" /> 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

elseif  ($Website == '' or (!preg_match("~^[a-z0-9.-]+\.(com|org|net|edu|co.uk)~i", $Website)))
else(isset($_POST['website']) &&  $_POST['website'] == 'true') 
{   												
die("<div class=\"form\">You completed the website field incorrectly, please try again</div>");
}

Link to comment
https://forums.phpfreaks.com/topic/237466-from-help/#findComment-1220244
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.