I need this field to only allow numbers to be input to the field and there must be 11 digits that have been input into the "Mobile Number" field, this is the form I have created
<form name="myForm" id="userDetails" action="formProcess.php" onSubmit="return validateForm()" method="post">
<fieldset class="custInf">
<h3> User Details </h3>
<label class="inputArea" for="fName">Forename :</label>
<input type="text" name="forename" id="fname" placeholder="Enter First Name" maxlength="20" size="15"></input>
<label class="inputArea" for="sName">Surname :</label>
<input type="text" name="surname" id="surname" placeholder="Enter Last Name" maxlength="20" size="15"></input>
<label class="inputArea" for="email">Email :</label>
<input type="email" name="email" id="email" placeholder="Enter Email Address" maxlength="40" size="15" /></input>
<label class="inputArea" for="hmph">Landline number :</label>
<input type="tel" name="landLineTelNo" id="hmphone" placeholder="Enter Landline no." maxlength="11" size="15"></input>
<label class="inputArea" for=" mobileTelNo">Mobile number :</label>
<input type="tel" name=" mobileTelNo" id="mobile" placeholder="Enter Mobile no." maxlength="11" size="15"></input>
<label class="inputArea" for="address">Postal Address :</label>
<input type="text" name="postalAddress" id="address" placeholder="Enter House no." maxlength="25" size="15"></input>
</fieldset>
<fieldset class="contactType">
<h3>
How would you like to be contacted?
</h3>
<label class="radioBt" for="sms">SMS</label>
<input id="smsBut" type="radio" name="sendMethod" value="SMS"></input>
<label class="radioBt" for="email">Email</label>
<input type="radio" name="sendMethod" value="Email"></input>
<label class="radioBt" for="post">Post</label>
<input type="radio" name="sendMethod" value="Post"></input>
</fieldset>
<fieldset class="termsCon">
<input type="checkbox" name="check" value="check" id="check" />I have read and agree to the Terms and Conditions and Privacy Policy</input>
</fieldset>
<input class="submitBut" type="submit" name="submitBut" value="Submit" </input>
Here is the PHP I have created so far to validate the user input `//Ensures user enters information required
$fname = $_REQUEST['forename'];
if (empty($fname)) {
die("<p>Enter a first name</p>\n");
}
$surname = $_REQUEST['surname'];
if (empty($surname)) {
die("<p>You must enter a surname</p>\n");
}
$email = $_REQUEST['email'];
if (empty($email)) {
die("<p>You need to enter an email</p>\n");
}
$hmphone = isset($_REQUEST['hmph']) ? $_REQUEST['hmph'] : null ;
$mobile = $_REQUEST['mobileTelNo'];
if (empty($mobile)) {
die("<p>Enter a Mobile Number</p>\n");
}
$address = $_REQUEST['postalAddress'];
if (empty($address)) {
die("<p>Enter your postal address</p>\n");
}
$sendMethod = $_REQUEST['sendMethod'];
if (empty($sendMethod)) {
die("<p>Please choose a contact option</p>\n");
}
$check = $_REQUEST['check'];
if (empty($check)) {
die("<p>Please select the Terms and Conditions to continue</p>\n");
}`
You can pattern match inside the form by adding the following code inside the relevant input field thanks to the html5 pattern tag. More details on the pattern tag here: http://www.w3schools.com/tags/att_input_pattern.asp
pattern="[0-9]{11}"
It's quite similar on the server side php checking thankfully!
$isValid = preg_match("/[0-9]{11}/", $formvalue);
$isValid will return true (1) if it matches or false (0) if it doesn't match.
preg_match is a very useful function in general for custom validation. There's more details on it available here: http://php.net/manual/en/function.preg-match.php
If you're sure your rule is correct you can do this:
if (empty($mobile) || preg_match('/^[0-9]{11}$/', $mobile) != 1 ) {
die("<p>Enter a Mobile Number</p>\n");
}
from the docs:
preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred.
The regular expression explained:
^ assert position at start of the string
[0-9] match a single character present in the list below
Quantifier: {11} Exactly 11 times
0-9 a single character in the range between 0 and 9
$ assert position at end of the string
you can validate with this:
if(empty($number)) {
echo '<p> Please enter a value</p>';
} else if(!is_numeric($number)) {
echo '<p> Data entered was not numeric</p>';
} else if(strlen($number) != 11) {
echo '<p> The number entered was not 6 digits long</p>';
}
Related
I am validating a form using PHP (very very basic form) and im wondering if there is a solution to not get this error Notice: Undefined index: sendMethod in /directory/... on line 26
here is my code that i have for my form:
<form name="myForm" id="userDetails" action="formProcess.php" onSubmit="return validateForm()" method="post">
<fieldset class="custInf">
<h3> User Details </h3>
<label class="inputArea" for="fName">Forename :</label>
<input type="text" name="forename" id="fname" placeholder="Enter First Name" maxlength="20" size="15">
</input>
<label class="inputArea" for="sName">Surname :</label>
<input type="text" name="surname" id="surname" placeholder="Enter Last Name" maxlength="20" size="15">
</input>
<label class="inputArea" for="email">Email :</label>
<input type="email" name="email" id="email" placeholder="Enter Email Address" maxlength="40" size="15" />
</input>
<label class="inputArea" for="hmph">Landline number :</label>
<input type="tel" name="landLineTelNo" id="hmphone" placeholder="Enter Landline no." maxlength="11" size="15">
</input>
<label class="inputArea" for="mobileTelNo">Mobile number :</label>
<input type="tel" name="mobileTelNo" id="mobile" placeholder="Enter Mobile no." maxlength="11" size="15">
</input>
<label class="inputArea" for="address">Postal Address :</label>
<input type="text" name="postalAddress" id="address" placeholder="Enter House no." maxlength="25" size="15">
</input>
</fieldset>
<fieldset class="contactType">
<h3> How would you like to be contacted? </h3>
<label class="radioBt" for="sms">SMS</label>
<input id="smsBut" type="radio" name="sendMethod" value="SMS">
</input>
<label class="radioBt" for="email">Email</label>
<input type="radio" name="sendMethod" value="Email">
</input>
<label class="radioBt" for="post">Post</label>
<input type="radio" name="sendMethod" value="Post">
</input>
</fieldset>
<fieldset class="termsCon">
<input type="checkbox" name="check" value="check" id="check" />I have read and agree to the Terms and Conditions and Privacy Policy
</input>
</fieldset>
<input class="submitBut" type="submit" name="submitBut" value="Submit" </input>
</form>
$fname = $_REQUEST['forename'];
if (empty($fname)) {
die("<p>Enter a first name</p>\n");
}
$surname = $_REQUEST['surname'];
if (empty($surname)) {
die("<p>You must enter a surname</p>\n");
}
$email = $_REQUEST['email'];
if (empty($email)) {
die("<p>You need to enter an email</p>\n");
}
//Landline not required so wont give error
$hmphone = isset($_REQUEST['hmph']) ? $_REQUEST['hmph'] : null ;
$mobile = $_REQUEST['mobileTelNo'];
if (empty($mobile)) {
die("<p>Enter a Mobile Number</p>\n");
}
$address = $_REQUEST['postalAddress'];
if (empty($address)) {
die("<p>Enter your postal address</p>\n");
}
$sendMethod = $_REQUEST['sendMethod'];
if (empty($sendMethod)) {
die("<p>Please choose a contact option</p>\n");
}
$check = $_REQUEST['check'];
if (empty($check)) {
die("<p>Please select the Terms and Conditions to continue</p>\n");
}
its a very basic PHP validation, i just want it to not give me a error notice until all over fields have been checked for example, the error shows up once all the fields are filled in saying "Please choose a contact option" but if i fill out all of the fields bar the mobile, i get the error notice
to avoid the notice, check if it's empty first
if (empty($_REQUEST['sendMethod']))
die("<p>Please choose a contact option</p>\n");
else
$sendMethod = $_REQUEST['sendMethod'];
I am using a custom optin page with a form , While testing and in work,When I submit the form I get all the details on my email except the phone number , I do not see any problem with the codes , I tried diff things like changing the value and stuff but it did not work, Here is the form code
<div class="form fix ">
<p class="form-text">Fill This Out and See Your <br>Timeshare Report</p>
<form name="contactform" action="mail-script.php" method="POST">
<label for="fname">First Name:
<input type="text" name="fname" id="fname" />
</label><br>
<label for="lname">Last Name:
<input type="text" name="lname" id="lname" />
</label><br>
<label for="email">Email Address:
<input type="text" name="email" id="email" />
</label><br>
<label for="phone">Phone Number:
<input type="text" name="phone" id="phone" />
</label><br>
<label for="phone">Alternate Phone:
<input type="text" name="phone" id="aphone" />
</label><br>
<label for="resort">Resort Name:
<input type="text" name="resort" id="resort" />
</label><br>
<label for="amount">Amount Owed? $:
<input type="number" name="amount" id="amount" />
<p style="font-size: 12px !important;margin-top: -14px;padding-right: 30px;text-align:right;">
If Paid Off Leave Zero, Else Put Amount</p>
</label><br>
<div class="checkbox">
<div class="check-text fix">
<p>I'm Considering To</p>
</div>
<div class="check-one fix">
<input type="checkbox" name="call" id="" value="sell"/> Sell It <br>
<input type="checkbox" name="call" id="" value="buy"/> Buy It <br>
<input type="checkbox" name="call" id="" value="rent "/> Rent It
</div>
<div class="check-two fix">
<input type="checkbox" name="call" id="" value="cancel"/> Cancel Mortgage <br>
<input type="checkbox" name="call" id="" value="ownership"/> End Ownership <br>
<input type="checkbox" name="call" id="" value="give"/> Give It Back
</div>
</div>
<p class="captcha">
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
</p>
<input id="submit" type="submit" value="" />
<p class="submit-text">Ensure all fields are completed and correct, allowing you more benefits, while preventing abuse of our data.</p>
</form>
</div>
</div>
This is the mail script which sends me the email
<?php
/* Set e-mail recipient */
$myemail = "**MYEMAIL**";
/* Check all form inputs using check_input function */
$fname = check_input($_POST['fname'], "Enter your first name");
$lname = check_input($_POST['lname'], "Enter your last name");
$email = check_input($_POST['email']);
$phone = check_input($_POST['phone']);
$resort = check_input($_POST['resort']);
$amount = check_input($_POST['amount']);
$call = check_input($_POST['call']);
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
Your contact form has been submitted by:
First Name : $fname
Last Name : $lname
E-mail: $email
Phone : $phone
Resort: $resort
Amount: $amount
Call : $call
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: index.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
if (strtolower($_POST['code']) != 'mycode') {die('Wrong access code');}
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
Here is the online url of the page
http://timesharesgroup.com/sell/index.html
You have two form elements with the same name. The second one overwrites the first one and you never receive it. You also forget your alternate phone number in your PHP code.
<label for="phone">Phone Number:
<input type="text" name="phone" id="phone" />
</label><br>
<label for="phone">Alternate Phone:
<input type="text" name="altphone" id="aphone" />
</label><br>
Your PHP:
$phone = check_input($_POST['phone']);
$altphone = check_input($_POST['altphone']);
Phone : $phone
Alt Phone : $altphone
Resort: $resort
Your alternative phone number is overwriting your phone number:
<label for="phone">Phone Number:
<input type="text" name="phone" id="phone" />
</label><br>
<label for="phone">Alternate Phone:
<input type="text" name="phone" id="aphone" />
^^^^^ here
</label><br>
Changing the name for the alternative number should fix that.
I have a page with a form, split into two halves with layout divs. The right hand side dynamically generates inputs based on a previous choice by the user as to how many users they are booking in.
The whole thing is handled by PHP. The form action is set to the page itself. On submission the form is validated and if this passes the user is redirected on to the next step. If the validation fails, error messages are generated appropriately.
It works fine in Firefox and Chrome, but not in IE11 except when set to IE8 compatibility mode. In IE11 (10 and 9 compatibility modes too), absolutely nothing happens when I click the submit button. No errors are logged to the console, nothing is submitted, the page does not reload. In IE8 mode, it works fine.
The only console warnings that occur on page-load are two unmatched end tags. The first mismatch it finds is the first closing </div> tag. The second mismatch is the closing </form> tag.
<div class="6u">
<form id="buy-form" name="details" action="booking3.php" method="post">
<fieldset>
<legend>Enter Billing Details</legend>
<label for="first_name" class="register">First Name</label>
<input type="text" id="fname" name="first_name" class="textbox booking required" size="20" maxlength="20"
value="<?php if (isset($_SESSION['first_name'])) {
echo $_SESSION['first_name'];
} ?>"/><br/>
<label for="last_name" class="register">Last Name</label>
<input type="text" id="lname" name="last_name" class="textbox booking required" size="20" maxlength="20"
value="<?php if (isset($_SESSION['last_name'])) {
echo $_SESSION['last_name'];
} ?>"/><br/>
<label for="email" class="register">E-mail Address</label>
<input type="email" id="emai" name="email" class="textbox booking required" size="20" maxlength="60"
value="<?php if (isset($_SESSION['email'])) {
echo $_SESSION['email'];
} ?>"/><br/>
<label for="telephone" class="register">Telephone</label>
<input type="text" id="tel" name="telephone" class="textbox phonenumber booking required" size="20"
maxlength="20" value="<?php if (isset($_SESSION['telephone'])) {
echo $_SESSION['telephone'];
} ?>"/><br/>
<label for="address">Billing Address</label>
<textarea class="order required" name="address"><?php if (isset($_SESSION['address'])) {
echo $_SESSION['address'];
} ?></textarea>
</fieldset>
</div>
<?php
if ($_SESSION['userno'] >= 1) { // if more than one user is selected, display text boxes to take extra user details
echo '<div class="6u content content-right">';
if ($_SESSION['userno'] == 1) {
echo '<span>Please enter the name, e-mail address and telephone number of your user.</span><br/>';
} else {
echo '<span>Please enter the names, e-mail addresses and telephone numbers of your '.$_SESSION['userno'].' users.';
}
for ($i = 0; $i < $_SESSION['userno']; $i++) { //create textboxes for the appropriate amount of users based on userno selection
echo '<fieldset><legend>User '.($i + 1).'</legend>';
if ($i == 0) {
echo '<label class="register">As Billing Details</label><input id="userisbooker" type="checkbox" class="booking"/><br/>';
}
echo '<label for="userFname[]" class="register">First Name: </label><input type="text" id="fname'.$i.'" name="userFname[]" class="textbox booking required" value="';
if (isset($_SESSION['userFname'][$i])) {
echo $_SESSION['userFname'][$i];
}
echo '"/><br/>';
echo '<label for="userLname[]" class="register">Last Name: </label><input type="text" id="lname'.$i.'" name="userLname[]" class="textbox booking required" value="';
if (isset($_SESSION['userLname'][$i])) {
echo $_SESSION['userLname'][$i];
}
echo '"/><br/>';
echo '<label for="userEmail[]" class="register">E-mail Address: </label><input type="email" id="email'.$i.'" name="userEmail[]" class="textbox booking required" value="';
if (isset($_SESSION['userEmail'][$i])) {
echo $_SESSION['userEmail'][$i];
}
echo '"/><br/>';
echo '<label for="userTel[]" class="register">Telephone: </label><input type="text" id="tel'.$i.'" name="userTel[]" class="textbox booking required" value="';
if (isset($_SESSION['userTel'][$i])) {
echo $_SESSION['userTel'][$i];
}
echo '"/><br/>';
echo '</fieldset>';
}
echo '<input class="button button-alt" type="submit" name="submit" value="Next >"/></form>';
}
?>
</div>
What is causing this problem in IE11? Are these two mismatched tags (which seem matched to me) enough to banjax the whole page?
This is how it should be ; do not close the element you're starting a form in before closing the form first.
<form id="buy-form" name="details" action="booking3.php" method="post">
<div class="6u">
<fieldset>
<legend>Enter Billing Details</legend>
<label for="first_name" class="register">First Name</label><input type="text" id="fname" name="first_name" class="textbox booking required" size="20" maxlength="20" value="<?php if(isset($_SESSION['first_name'])){echo $_SESSION['first_name'];}?>"/><br/>
<label for="last_name" class="register">Last Name</label><input type="text" id="lname" name="last_name" class="textbox booking required" size="20" maxlength="20" value="<?php if(isset($_SESSION['last_name'])){echo $_SESSION['last_name'];}?>"/><br/>
<label for="email" class="register">E-mail Address</label><input type="email" id="emai" name="email" class="textbox booking required" size="20" maxlength="60" value="<?php if(isset($_SESSION['email'])){echo $_SESSION['email'];}?>"/><br/>
<label for="telephone" class="register">Telephone</label><input type="text" id="tel" name="telephone" class="textbox phonenumber booking required" size="20" maxlength="20" value="<?php if(isset($_SESSION['telephone'])){echo $_SESSION['telephone'];}?>"/><br/>
<label for="address">Billing Address</label><textarea class="order required" name="address"><?php if(isset($_SESSION['address'])){echo $_SESSION['address'];}?></textarea>
</fieldset>
</div>
<?php
if ($_SESSION['userno'] >= 1){ // if more than one user is selected, display text boxes to take extra user details
echo '<div class="6u content content-right">';
if ($_SESSION['userno'] == 1){
echo '<span>Please enter the name, e-mail address and telephone number of your user.</span><br/>';
} else{
echo '<span>Please enter the names, e-mail addresses and telephone numbers of your '.$_SESSION['userno'].' users.';
}
for ($i = 0; $i < $_SESSION['userno']; $i++){ //create textboxes for the appropriate amount of users based on userno selection
echo '<fieldset><legend>User '. ($i+1).'</legend>';
if ($i == 0){
echo '<label class="register">As Billing Details</label><input id="userisbooker" type="checkbox" class="booking"/><br/>';
}
echo '<label for="userFname[]" class="register">First Name: </label><input type="text" id="fname'.$i.'" name="userFname[]" class="textbox booking required" value="'; if(isset($_SESSION['userFname'][$i])){echo $_SESSION['userFname'][$i];} echo'"/><br/>';
echo '<label for="userLname[]" class="register">Last Name: </label><input type="text" id="lname'.$i.'" name="userLname[]" class="textbox booking required" value="'; if(isset($_SESSION['userLname'][$i])){echo $_SESSION['userLname'][$i];} echo'"/><br/>';
echo '<label for="userEmail[]" class="register">E-mail Address: </label><input type="email" id="email'.$i.'" name="userEmail[]" class="textbox booking required" value="'; if(isset($_SESSION['userEmail'][$i])){echo $_SESSION['userEmail'][$i];} echo'"/><br/>';
echo '<label for="userTel[]" class="register">Telephone: </label><input type="text" id="tel'.$i.'" name="userTel[]" class="textbox booking required" value="'; if(isset($_SESSION['userTel'][$i])){echo $_SESSION['userTel'][$i];} echo'"/><br/>';
echo '</fieldset>';
}
echo '<input class="button button-alt" type="submit" name="submit" value="Next >"/>';
echo '</div>';
}
?>
</form>
I want my hidden input field to get the page title as its value.
This is my testmail.php code.
<p>From: <?php echo $_POST['name']; ?></p>
<p>Subject: <?php echo $_POST['subject']; ?></p>
<p>Email: <?php echo $_POST['email']; ?></p>
<p>Phone Number: <?php echo $_POST['phone']; ?></p>
<p style="width:300px;">Message: <?php echo $_POST['message']; ?></p>
and this is my form code
<form action="testmail.php" method="post" class="cf">
<label for="name">* Name:</label>
<input type="text" name="name" placeholder="Your Name">
<input type="hidden" name="subject" value="<?php value $_POST['pagetitle']; ?>">
<label for="email">* Email:</label>
<input type="text" name="email" placeholder="Enter a valid Email Address">
<label for="phone"> Phone:</label>
<input type="text" name="phone" placeholder="Enter areacode and number">
<label for="message">* Message:</label>
<textarea name="message"></textarea>
<button type="input">Send</button>
</form>
Is there a way to get the title automatically?
Here's a pure javascript way using the onsubmit event.
<form onsubmit="this.subject.value=document.title;">
<input type="text" name="subject" value="" />
<input type="submit" />
</form>
To give you a better understanding of the onsubmit event as the name suggests it executes the contained javascript when the user submits the form. The operation this.subject.value=document.title working from right to left basically says assign the value of document.title to the value attribute of the element with the name of subject in this specific form.
Using your existing form it should look like this (I added the onsubmit event and fixed up errors in your html as well as added the appropriate id's to form elements):
<form action="testmail.php" method="post" class="cf" onsubmit="this.subject.value=document.title;">
<label for="name">* Name:</label>
<input type="text" id="name" name="name" placeholder="Your Name" />
<input type="hidden" name="subject" value="" />
<label for="email">* Email:</label>
<input type="text" id="email" name="email" placeholder="Enter a valid Email Address" />
<label for="phone"> Phone:</label>
<input type="text" id="phone" name="phone" placeholder="Enter areacode and number" />
<label for="message">* Message:</label>
<textarea id="message" name="message"></textarea>
<input type="submit" name="submit" value="submit" />
</form>
This will set the value of your hidden input field once the page has finished loading.
<script>
$(function() {
$('input[name="subject"]').val($('title').text());
});
</script>
You can use JavaScript to do so, assuming you're using jQuery, bind submit event to your form
$('your_form_selector').on('submit', function(){
$('<input />').attr('type', 'hidden')
.attr('name', 'title')
.attr('value', document.title)
.appendTo($(this));
});
I am creating a web page where there are two divs (billing details and shipping details). When the page is loaded, the billing details are automatically displayed and the shipping details remain empty. I have included two radio buttons which allows the user to choose whether or not the shipping details are the same as the billing details. If the user selects yes from the radio buttons then the same details should be displayed in the shipping details.
Note: the details are stored in database are am using php to get the data displayed
At the moment, I have only tried using
<?php if(isset($_POST'[shipping'] == 'yes')){echo $fname} ?>
on the first name field just to see if it is working, but i doesnt seem to work.
<div id="leftprofile">
<form id="au" method="post" action="../../../coursework/coursework/scripts/checkout.php">
<fieldset class="billing">
<legend>Billing Details</legend><br />
<label for="fname" class="reglabel">First Name:</label>
<input required name="fname" type="text" id="fname" value="<?php echo $fname ?>"/><br />
<label for="lname" class="reglabel">Last Name:</label>
<input required name="lname" type="text" id="lname" value="<?php echo $lname ?>"/><br />
<label for="address" class="reglabel">Address:</label>
<input required name="address" id="address" type="text" value="<?php echo $address ?>"/><br />
<label for="town" class="reglabel">Town:</label>
<input required name="town" id="town" type="text" value="<?php echo $town ?>"/><br />
<label for="postcode" class="reglabel">Post Code:</label>
<input required name="postcode" id="postcode" type="text" value="<?php echo $postcode ?>"/><br />
<label for="phone" class="reglabel">Phone:</label>
<input required name="phone" id="phone" type="text" value="<?php echo $phone ?>"/><br />
<label for="email" id="EmailLabel" class="reglabel">E-mail:</label>
<input required name="email" type="email" id="email" value="<?php echo $email ?>"/><br />
</fieldset>
</form>
</div>
<div id="rightprofile">
<form id="au" method="post" action="../../../coursework/coursework/scripts/checkout.php">
<fieldset class="billing">
<legend>Shipping Details</legend><br />
<form>
Same as billing address?
<input type="radio" name="shipping" id="yes" value="yes">Yes
<input type="radio" name="shipping" id="no" value="no">No<br/>
</form>
<label for="fname" class="reglabel">First Name:</label>
<input required name="fname" type="text" id="fname" value="<?php if(isset($_POST'[shipping'] == 'yes')){echo $fname} ?>"/><br />
<label for="lname" class="reglabel">Last Name:</label>
<input required name="lname" type="text" id="lname" /><br />
<label for="address" class="reglabel">Address:</label>
<input required name="address" id="address" type="text" /><br />
<label for="town" class="reglabel">Town:</label>
<input required name="town" id="town" type="text" /><br />
<label for="postcode" class="reglabel">Post Code:</label>
<input required name="postcode" id="postcode" type="text" /><br />
<label for="phone" class="reglabel">Phone:</label>
<input required name="phone" id="phone" type="text" /><br />
<label for="email" id="EmailLabel" class="reglabel">E-mail:</label>
<input required name="email" type="email" id="email" /><br />
</fieldset>
</form>
</div>
I have written you some simplified example code. This site contains one form, with two input fields (billing and shipping), and one checkbox to check if the shipping information is the same as the billing information. If the checkbox is checked the code will simply ignore anything typed into 'shipping'.
This would achieve what you are asking for, at least from a PHP perspective. If you are looking more for the "copy the data in those input fields, to those input fields" in real time in the browser, then that is a task for Javascript, and not PHP.
<?php
/* Check if anything was submitted */
if(isset($_POST))
{
/* Retrieve billing information */
$billing_name = $_POST['billing_name'];
$billing_addr = $_POST['billing_addr'];
/* Check if shipping same as billing */
if(isset($_POST['same']))
{
/* Shipping is the same as billing */
$shipping_name = $billing_name;
$shipping_addr = $billing_addr;
}
/* If not, set shipping to the posted value */
else
{
$shipping_name = $_POST['shipping_name'];
$shipping_addr = $_POST['shipping_addr'];
}
$insert = mysql_query(...);
}
?>
<form method="post" action="#" />
Billing information
<label for="billing_name">Name</label>
<input type="text" id="billing_name" name="billing_name" />
<label for="billing_addr">Addr</label>
<input type="text" id="billing_addr" name="billing_addr" />
<label for="same" />Is the shipping information the same as billing information?</label>
<input type="checkbox" id="same" name="same" />
Shipping information
<label for="shipping_name">Name</label>
<input type="text" id="shipping_name" name="shipping_name" />
<label for="shipping_addr">Addr</label>
<input type="text" id="shipping_addr" name="shipping_addr" />
<input type="submit" value="Register" />
</form>