So, I am creating a simple form:
<tr>
<td>
<label for="FirstName">First Name <span class="req">*</span>
</label>
<br />
<input type="text" name="FirstName" id="FirstName" class="cat_textbox" maxlength="255" />
</td>
</tr>
<tr>
<td>
<label for="LastName">Last Name <span class="req">*</span>
</label>
<br />
<input type="text" name="LastName" id="LastName" class="cat_textbox" maxlength="255" />
</td>
</tr>
<input class="cat_button" type="submit" value="Submit" id="catwebformbutton" />
What I would like it to do is when the user click submit, it will take them to another page where those details will be confirmed, or simply shown to them. any ideas? or sample codes?
where the form ? I cant see any form in your code !
try create 2 php files
index.php file
<form action="next_page.php" method="post">
<table>
<tr>
<td>
<label for="FirstName">First Name <span class="req">*</span></label>
<br />
<input type="text" name="FirstName" id="FirstName" class="cat_textbox" maxlength="255" />
</td>
</tr>
<tr>
<td>
<label for="LastName">Last Name <span class="req">*</span></label>
<br />
<input type="text" name="LastName" id="LastName" class="cat_textbox" maxlength="255" />
</td>
</tr>
</table>
<input class="cat_button" type="submit" value="Submit" id="catwebformbutton" />
</form>
next_page.php file
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
echo "first Name : ".$FirstName."<br>";
echo "last Name : ".$LastName."<br>";
you want to use form method post and action form to do action in other page ,
and post data in another page using $_POST[]
Good references may be helpful to learn these things :
about form method ->
http://www.w3schools.com/tags/att_form_method.asp
about form action ->
http://www.w3schools.com/tags/att_form_action.asp
about $_POST in php ->
http://php.net/manual/en/reserved.variables.post.php
Related
I have a standard form with all user info, I want to have a drop down list where the state input is so the user can select the state. I have a database with state code and description. Here's the code for my form, just need to know how to add the drop down list so it will show up where the state code is. I've tried putting the drop down using the regular drop down code but when I do that the drop down list shows up at the top of the form.
<section class="main-container">
<div class="main-warpper">
<h2>Sign up</h2>
<form class="signup-form" action="includes/signupinc.php" method="POST">
<input type="text" name="mbrnumber" placeholder="Member Number">
<input type="text" name="alias" placeholder="Alias">
<input type="text" name="firstname" placeholder="First Name">
<input type="text" name="lastname" placeholder="Last Name">
<input type="text" name="address" placeholder="Address">
<input type="text" name="city" placeholder="City">
<input type="text" name="state" placeholder="State">
<input type="text" name="zipcode" placeholder="Zip Code">
<input type="text" name="email" placeholder="E-mail">
<input type="password" name="pwd" placeholder="Password">
<button = type="submit" name="submit">Sign Up</button>
</form>
</div>
</section>
I've been playing around with this and have come up with something like I want. I would like the state code drop down list to look like the placeholder in the rest of the form. Width height I know I can style this but not sure just how to do that. Here's the code I have come up with. The state drop down list comes from my database.
<section class="main-container">
<div class="main-warpper">
<h2>Sign up</h2>
<form class="signup-form" action="includes/signup.inc.php" method="POST">
<input type="text" name="clubname" placeholder="Your databae name(lower case only no spaces)">
<input type="text" name="mbrnumber" placeholder="Member Number">
<input type="text" name="alias" placeholder="Alias">
<input type="text" name="firstname" placeholder="First Name">
<input type="text" name="lastname" placeholder="Last Name">
<input type="text" name="address" placeholder="Address">
<input type="text" name="city" placeholder="City">
<tr>
<input type="text" name="state" placeholder="State">
<select name="state">
<?php
$sql="Select * from matchstates";
echo "<option value='' selected>Select State</option>";
foreach ($conn->query($sql) as $row) {
echo "<option value=$row[statecode]>$row[statename]</option>";
}
?>
</select>
</tr>
<input type="text" name="zipcode" placeholder="Zip Code">
<input type="text" name="email" placeholder="E-mail">
<input type="password" name="pwd" placeholder="Password">
<button = type="submit" name="submit">Sign Up</button>
</form>
</div>
I have a large amount of input fields. How can I pass the values into an array so I can pass the array from one page to another?
example:
<input type="text" value=<?php $arry = "compName" ?> placeholder="Company Name" />
Is this legal? How can I do this properly?
EDIT:
In my page, I have "add" and "delete" buttons that will add/delete more input fields. I also have a "preview" button at the bottom. User will add/delete before hitting preview. Preview will collect all input and will call the next page. So the amount of field is unknown.
Here's what my code/markup looks like:
<div class="panel" style="width: 98%; margin:0 auto">
<div class="row">
<div class="large-6 columns">
Advertiser Info: <hr>
<input type="text" value="compName" placeholder="Company Name" />
<input type="text" value= "adEmail" placeholder="Email" />
<input type="text" value="adContName" placeholder="Contact Name" />
<input type="text" value="adPhone" placeholder="Phone # (NO DASHES)" />
<input type="text" value="adStreet" placeholder="Street Address" />
<input type="text" value="adCity" placeholder="City" />
<input type="text" value="adState" placeholder="State/Provice" />
<input type="text" value="adZip" placeholder="Zip/Postal Code" />
<input type="text" value="adCountry" placeholder="Country" />
</div>
<div class="large-6 columns">
Billing Info: <hr>
<input type="text" value="bEmail" placeholder="Email" />
<input type="text" value="bContName" placeholder="Contact Name" />
<input type="text" value="bPhone" placeholder="Phone # (NO DASHES)" />
<input type="text" value="bStreet" placeholder="Street Address" />
<input type="text" value="bCity" placeholder="City" />
<input type="text" value="bState" placeholder="State/Provice" />
<input type="text" value="bZip" placeholder="Zip/Postal Code" />
<input type="text" value="bCountry" placeholder="Country" />
</div>
</div>
</div>
So when the user hits add and EXACT copy of above code will be made.
With that said, I want to be able to use PHP arrays for html values to pass. How can I set my inputs so that I can do this?
You can do some tweaks like:
Using input type elements as array elements.
So that:
<input type="text" name="elem[name]" value="<?php echo $YOUR_VALUE;?>"
<input type="text" name="elem[class]" value="<?php echo $YOUR_VALUE;?>"
<input type="text" name="elem[marks]" value="<?php echo $YOUR_VALUE;?>"
So that the variables are you are posting should be less.
In this case, you are posting only one variable instead of three.
Use Jquery to get all the values of input fields and make a json object of {input_name:value} or array variable of key value and then pass it in argument.
var key_value = {};
$('input').each(function(){
key_value[$(this).attr('name')]= $(this).val();
})
alert(JSON.stringify(key_value));
Now you have an object with field name as key and its value.
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>
i found few similar questions here but from answers i didn't get the whole picture of how should work.
I have a subscription form in a page:
<form method="post" action="index.php/register">
<fieldset>
<input type="text" id="first_name" name="first_name" />
<input type="text" id="last_name" name="last_name" />
<input type="text" id="email" name="email" />
<input type="text" id="address" name="address" />
<input id="submit" type="submit" value=">>" />
</fieldset>
</form>
when a user a user click the submit button is lead to a page with the full registering form, where i need to have few fields populated with the data sent from previous page form. this is a preview of few fields from the form of the second page:
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>*First Name</label>
<input type="text" id="first_name" name="first_name" />
</li>
<li>
<label>*Last Name</label>
<input type="text" id="last_name" name="last_name" />
</li>
<li>
<label>*Email</label>
<input type="text" id="email" name="email" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" id="address" name="address" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
the php is not my strong point, so if you can be more detailed in answer is great for me.
thanks!
I would say for security reasons, do not use Get method "$_GET[]" as people described, keep POST as you have it.
All you need to do on register/ page is get all the values passed on using the POST method and populate them into your HTML. So the second form should look like:
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>First Name</label>
<input type="text" id="first_name" name="first_name" value="<?=$_POST[first_name]?>" />
</li>
<li>
<label>*Last Name</label>
<input type="text" id="last_name" name="last_name" value="<?=$_POST[last_name]?>" />
</li>
<li>
<label>*Email</label>
<input type="text" id="email" name="email" value="<?=$_POST[email]?>" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" id="address" name="address" value="<?=$_POST[address]?>" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
Above, I am using shorthand version of "echo" and php tags, if you do not have that enabled under php.ini, please change "" to "; ?>. Also, script will not populate "confirm" email as I assume you would like the user to retype that.
That should do it.
There are basically two methods
Store the values of the first form in a cookie, and the process code can retrieve the values from the cookie
make the form action 'Get' so that the data is passed on to the next page.
You can use the $_POST values from the first form in the page handling the submit of the first form and print them in the new form as:
<?php
echo '<input type="text" id="email" name="email" value="' . htmlentities($_POST['email']) . '"/>
?>
<form method="post" action="register.php">
<fieldset>
<input type="text" id="first_name" name="first_name" />
<input type="text" id="last_name" name="last_name" />
<input type="text" id="email" name="email" />
<input type="text" id="address" name="address" />
<input id="submit" type="submit" value=">>" />
</fieldset>
</form>
register.php
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>*First Name</label>
<input type="text" value="<?php echo $_POST['first_name'];?>" id="first_name" name="first_name" />
</li>
<li>
<label>*Last Name</label>
<input type="text" value="<?php echo $_POST['last_name'];?>" id="last_name" name="last_name" />
</li>
<li>
<label>*Email</label>
<input type="text" value="<?php echo $_POST['email'];?>" id="email" name="email" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" value="<?php echo $_POST['address'];?>" id="address" name="address" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
Finally service the post in send_contact.php as you wish
I was told my client's quote form has not been generating very many emails. I have learned that although the form brings you to a confirmation page, the information never reaches the recipient.
I have altered the code so it goes to my office email for testing purposes. If I post code for the form elements below, would someone be able to spot what the problem might be?
Thank you very much!
Link to the quote page is http://autoglass-plus.com/quote.php
First is the form itself:
<form id="quoteForm" name="form" action="form/index.php" method="post">
<fieldset>
<p> <strong>Contact Information:</strong><br />
</p>
<div>
<label for="firstname">First Name:<br />
</label>
<input type="text" size="30" name="firstname" class="txt" id="firstname" />
</div>
<div>
<label for="lastname">Last Name:<br />
</label>
<input type="text" size="30" name="lastname" class="txt" id="lastname" />
</div>
<div>
<label for="address">Address:<br />
</label>
<input type="text" size="30" name="address" class="txt" id="address" />
</div>
<div>
<label for="city">City:<br />
</label>
<input type="text" size="30" name="city" class="txt" id="city" />
</div>
<div>
<label for="state">State:<br />
</label>
<input type="text" size="30" name="state" class="txt" id="state" />
</div>
<div>
<label for="zip">Zip:<br />
</label>
<input type="text" size="30" name="zip" class="txt" id="zip" />
</div>
<div>
<label for="label">Phone:<br />
</label>
<input type="text" size="30" name="phone" class="txt" id="label" />
</div>
<div>
<label for="email">Email:<br />
</label>
<input type="text" size="30" name="email" class="txt" id="email" />
</div>
<p><br />
<b>Insurace Information</b></p>
<p><i>Auto Glass Plus in an Approved Insurance Vendor. Insurance claims require additional information that we will request when we contact you for your quote.</i></p>
<br />
<div>
<input type="checkbox" name="insurance" value="yes" />
Check here if this is an insurance claim.<br />
<label for="year">Insurance Provider:<br />
</label>
<input type="text" size="30" name="provider" class="txt" id="provider" />
</div>
<p><br />
<b>Vehicle Information:</b><br />
</p>
<div>
<label for="year">Vehicle Year :<br />
</label>
<input type="text" size="30" name="year" class="txt" id="year" />
</div>
<div>
<label for="make">Make: </label>
<br />
<input type="text" size="30" name="make" class="txt" id="make" />
</div>
<div>
<label for="model">Model:</label>
<br />
<input type="text" size="30" name="model" class="txt" id="model" />
</div>
<div>
<label for="body">Body Type:<br />
</label>
<select name="body" id="body">
<option>Select One</option>
<option value="2 Door Hatchback">2 Door Hatchback</option>
<option value="4 Door Hatchback">4 Door Hatchback</option>
<option value="2 Door Sedan">2 Door Sedan</option>
<option value="4 Door Sedan">4 Door Sedan</option>
<option value="Station Wagon">Station Wagon</option>
<option value="Van">Van</option>
<option value="Sport Utility">Sport Utility</option>
<option value="Pickup Truck">Pickup Truck</option>
<option value="Other Truck">Other Truck</option>
<option value="Recreational Vehicle">Recreational Vehicle</option>
<option value="Other">Other</option>
</select>
</div>
<p><b><br />
Glass in Need of Repair:</b><br />
</p>
<div>
<input type="checkbox" name="repairs" value="Windshield" />
Windshield<br />
<input type="checkbox" name="repairs" value="Back Glass" />
Back Glass<br />
<input type="checkbox" name="repairs" value="Driver’s Side Window" />
Side Window*<br />
<input type="checkbox" name="repairs" value="Chip Repair" />
Chip Repair<br />
<input type="checkbox" name="repairs" value="Other" />
Other </div>
<p><strong>*Important:</strong> For side glass, please indicate the specific window that needs replacement <i>(e.g. passenger side rear door or driver side vent glass)</i>, and any tinting color preference in the <strong>Describe Damage </strong> field.</p>
<p><br />
<b>Describe Damage</b></p>
<div>
<textarea rows="6" name="damage" id="damage" cols="37" class="txt"></textarea>
</div>
<input type="hidden" name="thanks" value="../thanks.php" />
<input type="hidden" name="required_fields" value="firstname, lastname, email, phone" />
<input type="hidden" name="html_template" value="testform.tpl.html" />
<input type="hidden" name="mail_template" value="testmail.tpl.txt" />
<div class="submit">
<center>
<input type="submit" value="Submit Form" name="Submit" id="Submit" />
</center>
</div>
</fieldset>
</form>
Then it sends to a file named index.php inside the "form" folder:
<?php
$script_root = './';
$referring_server = 'www.wmsgroup.com, wmsgroup.com, scripts';
$allow_empty_referer = 'yes'; // (yes, no)
$language = 'en'; // (see folder 'languages')
$ip_banlist = '';
$ip_address_count = '0';
$ip_address_duration = '48';
$show_limit_errors = 'yes'; // (yes, no)
$log_messages = 'no'; // (yes, no)
$text_wrap = '65';
$show_error_messages = 'yes';
$attachment = 'no'; // (yes, no)
$attachment_files = 'jpg, gif,png, zip, txt, pdf, doc, ppt, tif, bmp, mdb, xls, txt';
$attachment_size = 100000;
$path['logfile'] = $script_root . 'logfile/logfile.txt';
$path['upload'] = $script_root . 'upload/'; // chmod 777 upload
$path['templates'] = $script_root . 'templates/';
$file['default_html'] = 'testform.tpl.html';
$file['default_mail'] = 'testmail.tpl.txt';
/*****************************************************
** Add further words, text, variables and stuff
** that you want to appear in the templates here.
** The values are displayed in the HTML output and
** the e-mail.
*****************************************************/
$add_text = array(
'txt_additional' => 'Additional', // {txt_additional}
'txt_more' => 'More' // {txt_more}
);
/*****************************************************
** Do not edit below this line - Ende der Einstellungen
*****************************************************/
/*****************************************************
** Send safety signal to included files
*****************************************************/
define('IN_SCRIPT', 'true');
/*****************************************************
** Load formmail script code
*****************************************************/
include($script_root . 'inc/formmail.inc.php')
?>
There is also formail.inc.php, testform.tpl.php, testform.tpl.text and then the confirmation page, thanks.php
I want to know how these all work together and what the problem could be.
Your form appears to be using the GentleSource.com Form Mail package. I suggest starting from scratch with a fresh download of their source zip or tar.gz files in a subdirectory. Then run through their installation instructions, test it. Then get it customized in the way your prior form worked.
This is in response to your question "how these all work together".
The user enters information on quote.php page. When the page is submitted, it is sent to form/index.php for processing. This file does some checks and formats the information entered two ways, one way for html email using the template testform.tpl.php and a second way for text email using the form testform.tpl.text. The information is then passed to formmail.inc.php which sends the email and then to thanks.php which displays the response to the user.
What the problem could be? Look at the formmail.inc.php file and make sure that it is properly configured for your server and php installation.
You should make sure that the e-mail addresses in the mail template mail.tpl.txt have the correct format. E-mail addresses should be in angle brackets:
From: <visitor#example.com>
If you're using the fields firstname and lastname, they need to be in quotes:
From: "{firstname} {lastname}" <vistor#example.com>
Other possibilities, why the script won't send e-mails: Windows server with no MTA. Mails get caught by a spam filter somewhere on the way.
You should test if the server can even send e-mails:
<?php
mail('your-email#example.com', 'Test-Subject', 'Test-Message');
?>