Create a back button for form - php

I've created a 2 step form with the following code:
<form class="form" method="POST" action="<?php bloginfo('url'); ?>/contact-us/">
<? if (!$_POST['step']) { ?>
<h1>Step 1 of 2</h1><br />
<input type="hidden" name="step" value="1" />
<table border="0" width="100%">
<tr>
<td>
<input type="text" name="title" id="title" value="Title*" />
</td>
</tr>
</table>
<button class="continue-button" type="submit" name="submit">Continue</button>
<? } else if ($_POST['step'] == 1) {
foreach($_POST as $name => $value) {
if ($name <> "step") { echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />"; }
} ?>
<h1>Step 2 of 2</h1><br />
<input type="hidden" name="step" value="2" />
<table border="0" width="100%">
<tr>
<td>
<input type="text" name="name" id="name" value="Name*" />
</td>
</tr>
</table>
<button class="continue-button" type="submit" name="submit">submit</button>
<? } else if ($_POST['step'] == 2) { //do stuff
echo "Do stuff here";
} ?>
</form>
How can I add a back button on step 2? There will be several steps added not just 2 so the user needs to be able to move forward and back through the steps whilst keeping what they've filled in.

Try this
<form class="form" method="POST" action="<?php bloginfo('url'); ?>/contact-us/">
<? if (!$_POST['step']) { ?>
<h1>Step 1 of 2</h1><br />
<input type="hidden" name="step" value="1" />
<table border="0" width="100%">
<tr>
<td>
<input type="text" name="title" id="title" value="<?= $_REQUEST["title"]?>" placeholder="Title*" />
</td>
</tr>
</table>
<button class="continue-button" type="submit" name="submit">Continue</button>
<? } else if ($_POST['step'] == 1) {
$field ="";
foreach($_POST as $name => $value) {
if ($name <> "step") { echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />"; $field .= $name."=".$value."&";}
} ?>
<div><a href="<?php bloginfo('url'); ?>/contact-us/?<?= $field ?>" >Back</a></div>
<h1>Step 2 of 2</h1><br />
<input type="hidden" name="step" value="2" />
<table border="0" width="100%">
<tr>
<td>
<input type="text" name="name" id="name" value="Name*" />
</td>
</tr>
</table>
<button class="continue-button" type="submit" name="submit">submit</button>
<? } else if ($_POST['step'] == 2) { //do stuff
echo "Do stuff here";
} ?>
</form>

First add it on top of your page
// keep the data
$_SESSION['data'] = $_POST;
$_SESSION['step'] = $_REQUEST['step'];
Also replace the if statement to something like this:
if ($_REQUEST['step'] == 1) {
// continue
Write dynamic values on your form
<input type="text" name="title" id="title"
value="<?php echo $_SESSION['data']['title']; ?>" />
Use a link for Back and Next:
Back
Next
I guess it would works for you! :)

To navigate back and forwards you will want to pass the data from the previous form back to it again so you would need to store the value of each form somewhere. Your best bet would be to create a session and store each form info in a session variable. Then when you load each form you should check to see if the data is already stored in a session.
Then you could add a jquery button to change the value of the step and submit the form.
To do this you would need to the 'step' hidden input an id like 'step'
<input type="hidden" name="step" id="step" value="2" />
and then add a button like
<button class="back-button" type="submit" name="back" onclick="$('#step').val('1');">Back</button>
This would change the value of the step input and then submit the form taking you back to the previous form.
You would need to have another hidden input to tell the form where it came from so it would know whether to look at the session data (is you're going backwards) or the POST data (if youre going forwards).

Related

2 forms on same page php

My studybook gives me an assignment which requires me to have 2 forms on one page and output them both to the same page. Is this even possible? Both forms work fine independently. Both have the action:
<?php echo $_SERVER['PHP_SELF']; ?>".
Both have a submit button, but the button only submits the form it's part of. This probably makes sence though.
Thing is i need the page to either post both form outputs when clicking one of the 2 submit buttons or press them subsequently but the information from the first form needs to stay on the page.
Is this possible or am i trying do to the impossible?
the forms are as follows;
form 1:
<form name="orderform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Korting:
<tr>
<td>
<input type="checkbox" name="korting[]" value=15 /> Student 15% <br>
<input type="checkbox" name="korting[]" value=10 /> Senior 10% <br>
<input type="checkbox" name="korting[]" value=5 /> Klant 5% <br>
<hr />
</td>
</tr>
<tr>
<td>
betalingswijze
<input type="radio" name="betalingswijze" value="paypal"> Paypal
<input type="radio" name="betalingswijze" value="mastercard"> Mastercard
<input type="radio" name="betalingswijze" value="visa"> Visa
<hr />
</td>
<tr>
<td>
<img src="toshiba.jpg" alt=" " />
</td>
</tr>
<tr>
<td>
Toshiba Sattelite A100-510 Basisprijs 999.99
</td>
</tr>
<tr>
<td><!--Shopping Cart Begin-->
<input type="hidden" name="toshibaproduct" value="001" />
<input type="hidden" name="toshibamerk" value="toshiba" />
<input type="hidden" name="toshibamodel" value="Sattelite A100-510" />
Operating system <select name="toshibaos" value="Toshiba">
<option value="xp">Windows XP</option>
<option value="vista">Windows Vista</option>
<option value="linux">Linux</option>
</select>
Aantal: <input type="text" size=2 maxlength=3 name="toshibaaantal" value="0" />
<input type="hidden" name="toshibaprijs" value="999.99" />
<input type="image" src="bestel.jpg" border=0 value="bestellen" />
<hr />
<tr>
<td>
<img src="acer.jpg" alt=" " />
</td>
</tr>
<tr>
<td>
Acer Aspire 5735Z Basisprijs 529.99
</td>
</tr>
<tr>
<td>
<input type="hidden" name="acerproduct" value="002" />
<input type="hidden" name="acermerk" value="acer" />
<input type="hidden" name="acermodel" value="Aspire 5735Z" />
Operating system <select name="aceros" value="Acer">
<option value="xp">Windows XP</option>
<option value="vista">Windows Vista</option>
<option value="linux">Linux</option>
</select>
Aantal: <input type="text" size=2 maxlength=3 name="aceraantal" value="0" />
<input type="hidden" name="acerprijs" value="529.99" />
<input type="image" src="bestel.jpg" border=0 value="bestellen" />
<hr />
</td><!--Shopping Cart End-->
</tr>
</form>
Form 2
<form name="klant gegevens" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border=1 >
<tr>
<td colspan="2">
<b>Factuur klantgegevens</b>
</td>
</tr>
<tr>
<td width="100">Naam: </td>
<td>
<input type="text" sie="55" name="naam" />
</td>
</tr>
<tr>
<tr>
<td>Adres: </td>
<td>
<input type="text" sie="55" name="adres" />
</td>
</tr>
<tr>
<td>Woonplaats:</td>
<td>
<input type="text size="34" name="woonplaats">
Postcode:<input type="text" size="6" name="postcode">
</td>
</tr>
<tr>
<td>e-mail:</td>
<td>
<input type="text" size="55" name="email">
</td>
</tr>
<tr>
<td>Feedback:</td>
<td>
<textarea cols="40" rows="3" name="commentaar">
</textarea>
</td>
</tr>
</table>
<input type="image" src="checkout.png" value="send"/>
</form>
Both have functions which kick in on submit. Sorry for the spacings. I have them better in my own files but i just don't know how to get them right on this site.
Greetings,
Lennart
The action represent the page that will receive the posted data. You may use differents actions or the same action with different parameters.
If you use the same action, you had to insert a parameter that permit to manage different cases. You may insert an hidden field to do this.
Consider these simple forms:
<form name="form_a" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="form" value="A">
<button type="submit">Form A</button>
</form>
<form name="form_b" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="form" value="B">
<button type="submit">Form B</button>
</form>
To manage the different submission, you had to check the value of the hidden field:
if(isset($_POST['form'])){
switch ($_POST['form']) {
case "A":
echo "submitted A";
break;
case "B":
echo "submitted B";
break;
default:
echo "What are you doing?";
}
}
You can't submit two separate forms at the same time, because each submission represent a different request to the server.
You may merge manually the fields of the two forms, or use Javascript to do this for you.
Keep in mind that if you do this via Javascript, the field of the forms had to have differents names.
As you caan see here you can do simply via jQuery:
var str1 = $("form_a").serialize();
var str2 = $("form_b").serialize();
$.post(url, str1 + "&" + str2);
Where url is the action params of the form
Your form should be like this.
First form
<form method="post" >
...
<input type="hidden" name="form1submission" value="yes" >
<input type="submit" name="submit" value="Submit" >
</form>
Second form
<form method="post" >
...
<input type="hidden" name="form2submission" value="yes" >
<input type="submit" name="submit" value="Submit" >
</form>
And your php for first form.
if('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['form1submission'])) {
// first form code.
}
And second form php code.
if('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['form2submission'])) {
// second form code.
}
That's it.
DUPLICATE POST
Yes you can!
First, add the proper action to all forms, secondly, give them an unique name
HTML Side
Don't forget to add the http method what you want (GET or POST)
<form method="post">
<input type="hidden" name="orderform" />
<!-- rest of form goes here -->
</form>
<form method="post">
<input type="hidden" name="klant_gegevens" />
<!-- rest of form goes here -->
</form>
Leaving the action-attribute empty or removing it entirely will make the form submit to the current page (see this post), and usage of $_SERVER["PHP_SELF"] can lead to XSS-injection read under "Big Note on PHP Form Security"
Note:
Avoid using space for field names, it can make some problem to match them...
PHP Side
getting input values, by filtering on received form name
if (isset($_POST["orderform"])) {
// The first form was submitted
}
if (isset($_POST["klant_gegevens"])) {
// The second form was submitted
}
Note:
Use print_r() or var_dump(), to debug the content of exchanged values

Using one form to fill in two other forms

OK so I have two different types of forms and I want to use one form to submit them both. I am using a auto-responder form for form1 fields= first, last and email. My second form is a contact me form fields= name. email and a body field. I am trying to use both these forms at one shot. I have a form that will post fields to each form (INDEX.PHP) the problem is I am not sure how to set up form one to post fields into form1 and form2 the way I want. I want to use the fields that match from form index.php to both the other forms (form1, form2). so name and email will go to both forms and the body field will go to form2. The main form will post first and last in the name field of form2....also as you can see from form 1 and 2 each form has a some sort of redirect page I need to work around.?
I have main form:
Index.php
<html>
<head>
<title>Main Form</title>
</head>
<body>
<h2>Winner Aution Item Request Form</h2>
<p><span class="error"><FONT><font color="red">* required field.</font></span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
First Name: <input type="text" name="first_name" value="<?php echo $first_name;?>">
<FONT><font color="red"> *</font>
<br>
Last Name: <input type="text" name="last_name" value="<?php echo $last_name;?>"> <FONT><font color="red"> *</font>
<br>
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
<FONT><font color="red"> *</font>
<br><br><i><b>Copy and paste auction item name below.</b></i><br>
Product Name: <input type="text" name="product_Name" rows="1" cols="10">
<?php echo $product_Name;?><FONT><font color="red"> *</font>
<input type="Submit" value="Submit" name="submit"></input>
</form>
</body>
</html>
the above form was found on a website and was pretty close to what I want it to do but not exactly....
Form1
<?php session_start(); ?>
<html>
<head>
<title>autoresponder</title>
</head>
<body>
<center>
<table cellspacing="10" bgcolor="#CCCCCC" style="border: 0px solid #000000;">
<tr><td>
<form action="http://newsletter.jeremyahenry.com//s.php" method=GET>
<strong><font color="#660000">Your First Name:</font></strong>
<input type="text" name="f" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#660000">Your Last name:</font></strong>
<input type="text" name="l" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#000066">Email address:</font></strong><br>
<input type="text" name="e" style="background-color : #FFFFFF" size=20 maxlength=50>
<input type="image" src="http://blog.jeremyahenry.com/mailermanager/images/go-button.gif" name="submit" value="Submit"><br>
<input type="hidden" name="r" value="4">
<input type="hidden" name="a" value="sub">
<input type="hidden" name="ref" value="none">
<br>
<font color="#003300">HTML: <input type="RADIO" name="h" value="1">Yes
<input type="RADIO" name="h" value="0" checked="checked">No<br>
</font>
</form>
</td></tr>
</table>
</center>
</body>
</html>
Form 2
<?php session_start(); ?>
<html>
<head>
<title>request form</title>
<style>p{font:10pt arial;}</style>
</head>
<body>
<form action="contact_me/process.php" method=post>
<table align=left border=0 height=300>
<tr>
<td nowrap>
<p> Your name:
<input maxlength=25 name=name size=25>
</td>
</tr>
<tr>
<td nowrap>
<p> Your email:
<input name=from size=25 maxlength=25>
</td>
</tr>
<tr>
<td colspan=2>
<center>
<p align=center>Enter your Auction item Name below:
<br>
<textarea cols=50 name=message rows=7></textarea>
<p align=center>
<input type=submit value="Send Message">
<input type=reset value=Reset name="reset">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
ass you can see from the code I was going to use sessions. But not to familiar with it even though I have experience with php I am still quite new to it and need help. I want to pars form data to both forms. and the product name to form two. any help on this would be greatly appreciated.. I hope this is clear enough for some one out there to help.....
Ok New code Three forms 1.main form submits information to form1 and form2.
I have set up using a session so I have: session.php
<?php
session_start();
// store session data
$_SESSION['af_first_name'] = $af_first_name;
$_SESSION['af_last_name'] = $af_last_name;
$_SESSION['af_email'] = $af_email;
$_SESSION['cf_address'] = $cf_item_name;
?>
That handles variables.
My new code for index.php
<?php
// including the session file
require_once("session_start.php")
?>
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
?>
</head>
<body>
<h2>Winner Aution Item Request Form</h2>
<p><span class="error"><FONT><font color="red">* required field.</font></span></p>
<form name="form1">
First Name: <input type="text" name="$af_first_name" id="af_first_name" value="<?php if(isset($_SESSION['af_first_name'])){echo stripslashes($_SESSION['af_first_name']); unset($_SESSION['af_first_name']); } ?>" /><br>
Last Name: <input type="text" name="$af_last_name" id="af_last_name" value="<?php if(isset($_SESSION['af_last_name'])){echo stripslashes($_SESSION['af_last_name']); unset($_SESSION['af_last_name']); } ?>" /><br>
E-Mail: <input type="text" name="$af_email" id="af_email" value="<?php if(isset($_SESSION['af_email'])){echo stripslashes($_SESSION['af_email']); unset($_SESSION['af_email']); } ?>" /><br>
</form>
<form name="form2">Copy and Paste Auction Name Below!<br>
Product Name <br><input type="text" name="$cf_item_name" id="cf_item_name" value="<?php if(isset($_SESSION['cf_item_name'])){echo stripslashes($_SESSION['cf_item_name']); unset($_SESSION['cf_item_name']); } ?>" /><br>
<input type="Submit" value="Submit" name="submit" onsubmit="form2.submit(); form3.submit();"></input>
That form takes input and sets to session. Session.php picks it up and places it in variable form. From here I used a strip for the underscores. and when it goes to form1 and form2 varables pick it up and fill in the form. Here is my new form1
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
if(!empty($_SESSION['_mf'])): //Strip all possible back slashes
stripZlashes($_SESSION['_mf']);
endif;
// including the session file
require_once("session_start.php")
?>
<center>
<table cellspacing="10" bgcolor="#CCCCCC" style="border: 0px solid #000000;"> <tr><td>
<form action="http://newsletter.jeremyahenry.com//s.php" method=GET>
<strong><font color="#660000">Your First Name:</font></strong>
<input type="text" id="$af_first_name" value="<?php echo (!empty($_SESSION['_af']['af_first_name'])?$_SESSION['_af']['af_first_name']:'') ?>" name="f" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#660000">Your Last name:</font></strong>
<input type="text" id="$af_last_name" value="<?php echo (!empty($_SESSION['_af']['af_last_name'])?$_SESSION['_af']['af_last_name']:'') ?>" name="l" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#000066">Email address:</font></strong><br>
<input type="text" id="$af_email" value="<?php echo (!empty($_SESSION['_af']['af_email'])?$_SESSION['_af']['af_email']:'') ?>" name="e" style="background-color : #FFFFFF" size=20 maxlength=50>
<input type="image" src="http://newsletter.jeremyahenry.com/images/go-button.gif" name="submit" value="Submit"><br>
<input type="hidden" name="r" value="4">
<input type="hidden" name="a" value="sub">
<input type="hidden" name="ref" value="none">
<br>
<font color="#003300">HTML: <input type="RADIO" name="h" value="1">Yes
<input type="RADIO" name="h" value="0" checked="checked">No<br>
</font></form>
</td></tr></table>
</center>
<?php
if(!empty($_SESSION['_mf'])):
unset($_SESSION['_mf']);
endif;
?>
form2:
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
if(!empty($_SESSION['_mf'])): //Strip all possible back slashes
stripZlashes($_SESSION['_mf']);
endif;
// including the session file
require_once("session_start.php")
?>
<form action="process.php" method=post>
<table align=left border=0 height=300>
<tr>
<td nowrap>
<p> Your name:
<input maxlength=25 name="af first name" id="af_first_name" value="<?php echo (!empty($_SESSION['_af']['af_first_name'])?$_SESSION['_af']['af_first_name']:'') ?>" size=25> />
</td</tr>
<tr>
<td nowrap>
<p> Your email:
<input name=af email id="af email" value="<?php echo (!empty($_SESSION['_af']['af_email'])?$_SESSION['_af']['af_email']:'') ?>" size=25 maxlength=25> />
</td></tr>
<tr>
<td colspan=2>
<center>
<p align=center>Enter your Auction item Name below:
<br>
<input name="cf item name" id="cf item name" value="<?php echo (!empty($_SESSION['_cf']['cf_item_name'])?$_SESSION['_cf']['cf_item_name']:'') ?>" rows="1" />
<p align=center>
<input type=submit value="Send Message">
</td></tr></table>
</form>
</center>
Ok now i have an issue with it submitting correctly...
<form name="form1">
<input type="text" value="" name="somename" onkeyup="form2.somename.value=this.value" />
</form>
<form name="form2">
<input type="text" value="" name="somename" />
</form>
check out the above code. hope this could be helpful. Or if this is not the result which you require. so you can be brief with your requirements in reply.
I don't know the usage or need of your implementation: maybe it is like a 3 step registration form?
It could be done in different ways without complicating it too much.
You could put all three forms in the same page and only showing the right one
according to th data being posted to the same page. It is the old way of doing things.
With Ajax calls, templates and javascript it could be don simpler but it depends on
your experience.
on each element you can mention as per their relevent events, such as
Ex. onkeyup="form2.elementname.value=this.value"

Multiple forms on same page - If empty

I'm currently in the process of coding a MySQL search page and I'm unable to work out how to make it so that if there's no data put in one form it'll do nothing, and if there's data in the other form it'll search the database for that value.
<?PHP
echo '<h3 class="hp-1">Kick Logs</h3><div class="wrapper">
<div class="logcol-1"><form name="form1" id="mainForm" method="post"enctype="multipart/form-data" action="' . $_SERVER['REQUEST_URI'] . '">
<input name="name" type="text" id="name" placeholder="Players Name">
</form>';
echo '<form name="form2" id="mainForm" method="post"enctype="multipart/form-data" action="' . $_SERVER['REQUEST_URI'] . '"><input name="reason" type="text" id="reason" placeholder="Kick Reason"></form>';
$name = mysql_real_escape_string($name);
$reason = mysql_real_escape_string($reason);
$kicklogname = mysql_query("SELECT * FROM `log1` WHERE `user` LIKE '%$name%'") or die(mysql_error());
$kicklogreason = mysql_query("SELECT * FROM `log1` WHERE `user` LIKE '%$reason%'") or die(mysql_error());
if($name == ""){
echo "You must enter a name to search"; }
else {
echo '<table width="700" border="0">
<tr class="listheader">
<td width="100" bgcolor="#afe6ff">Username</td>
<td width="220" bgcolor="#afe6ff">Reason</td>
</tr>';
while($row = mysql_fetch_array($kicklogname))
{
echo '<tr><td bgcolor="#daf4ff" class="contentleft">';
echo $row['user'];
echo '</td><td bgcolor="#eefaff" class="contentright">';
echo $row['reason'];
echo '</td></tr>';
}
echo '</table></div></div>';
}
?>
Update
Sorry, re-read the question. To check multiple forms on the same page you need to add a submit button to each form and give it a name:
<?php
if (!empty($_POST) && isset($_POST['reasonsubmit'])) {
echo 'Submitted reason form';
}
if (!empty($_POST) && isset($_POST['namesubmit'])) {
echo 'Submitted name form';
}
?>
<form action="reason.php" method="post">
<input type="text" name="reason" id="reason" />
<input type="submit" name="reasonsubmit" />
</form>
<form action="name.php" method="post">
<input type="text" name="name" id="name" />
<input type="submit" name="namesubmit" />
</form>
Alternatively, if you didn't want to give the submit button a name you can just add a hidden field to each form and you will get the same behavior.
<form action="reason.php" method="post">
<input type="hidden" name="reasonsubmit" id="reasonsubmit" />
<input type="text" name="reason" id="reason" />
<input type="submit" />
</form>
<form action="name.php" method="post">
<input type="hidden" name="namesubmit" id="namesubmit" />
<input type="text" name="name" id="name" />
<input type="submit" />
</form>

HTML form second button wont search my database

I have a database set up called customer. I also have a form that allows me to enter data into that database when submit, which is working fine.
However I also want to be able to search the database on the same page. I added a search field and button, and tried to use an if statement to determine which button was pressed.
The second button for searching the database doesn't seem to be doing anything when pressed, it doesn't seem to even enter the else if statement and I can't see why.
I have the following code:
<?php
require("header.php");
connect('final');//connect to DB
header ("location:/xampp/newCustomer.php");
if (isset($_POST['add'])) {
//do stuff for submit button here which works fine
}
else if (isset($_POST['btnSearch'])){
echo 'searching'; // test if button is working
$query = $_POST['searching'];
$data = mysql_query("SELECT *FROM customer WHERE 'First_Name' LIKE '$query'") ;
if($data === FALSE) {
$error = 'Query error:'.mysql_error();
echo $error;
}
else
{
$test = array();
$colNames = array();
while($results = mysql_fetch_assoc($data))
{
$test[] = $results;
}
$anymatches=mysql_num_rows($data);
if ($anymatches != 0)
{
$colNames = array_keys(reset($test));
}
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
}
}
}
?>
With my form setup like this:
<form name="add" action="newCustomer.php" method="post">
<label><span></span> <input type="text" name="query" palceholder="Type to Search" id="seaching"/></label>
<br />
<label><span>Name</span> <input type="text" name="addFname" /></label>
<button type="button" name="btnSearch" value="Search" id="btnSearch" onclick="this.form.action">Search</button></label>
<input type="hidden" name="searching" value="true" />
<input type="hidden" name="searching" value="true" />
<button type="submit" name="add" value="add" id="btnSub" >Add</button></label>
</form>
</html>
you use type="button", that gives it a button structure but a button dont sumbit a form only a submit does that.
<form name="add" action="newCustomer.php" method="post">
<label><span></span> <input type="text" name="query" palceholder="Type to Search" id="seaching"/></label>
<br />
<label><span>Name</span> <input type="text" name="addFname" /></label>
<button type="button" name="btnSearch" value="Search" id="btnSearch" onclick="this.form.action">Search</button></label>
<input type="hidden" name="searching" value="true" />
<input type="hidden" name="searching" value="true" />
<button type="submit" name="add" value="add" id="btnSub" >Add</button></label>
</form>
</html>
Try this:
HTML:
<form action="NewCustomer.php" method="post">
<table>
<tr>
<td> Name: </td>
<td><input type="text" name="name"></td>
<td><input type="submit" name="add" value="add"></td>
</tr>
</form>
<form action="NewCustomer.php" method="post">
<tr>
<td>Search: </td>
<td><input type="text" name="search"></td>
<td><input type="submit" name="search" value="search"></td>
</tr>
</table>
</form>
And PHP:
<?php
if (isset($_POST['add'])) {
echo "add";
}
if (isset($_POST['search'])){
echo "search";
}
?>
I think this is what you need :)

getting url value in input box

In my html page, i have links like this
<table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td><img src="images/box4.png" width="230" height="300" /></td>
<td><img src="images/box1.png" width="230" height="300" /></td>
<td><img src="images/box2.png" width="230" height="300" /></td>
<td><img src="images/box3.png" width="230" height="300" /></td>
</tr>
</table>
When i click on any one of the image, it will go to ApplicationRegister.php page with plan= corresponding values.
In my ApplicationRegister.php i have a registration form
<form action="emailconfirmation.php" method="post" name="form1" id="form1" onsubmit="return Validate();">
Company Name:
<input type="text" name="CompanyName" style="width:230px; height:20px;" /><br /><br />
Company E-mail :
<input type="text" name="Companyemail" style="width:230px; height:20px;" /><br /><br />
Company Contact <input type="text" name="CompanyContact" style="width:230px; height:20px;" /><br /><br />
Company Address: <input type="text" name="CompanyAddress" style="width:230px; height:20px;" /><br /><br />
<input type="hidden" name="form_submitted" value="1"/>
<input type="submit" value="REGISTER" name="submit" />
</form>
In this page it should take the value from url like plan=trail or plan1... whatever there in the url. then while submitting all the values should be submitted along with these form data.
How to achieve this? Please help.
First, you need to sanitize the plan input:
<?php
$plan = #$_GET['plan'];
$plan = +$plan; #convert to number
?>
Just add another hidden field containing that value
<form action="emailconfirmation.php" method="post" name="form1" id="form1" onsubmit="return Validate();">
...
<input type="submit" value="REGISTER" name="submit" />
<input type="hidden" name="plan" value="<?php echo $plan ?>"/>
</form>
Another option would be to add it as a get parameter to the action:
<form action="emailconfirmation.php?plan=<?php echo $plan ?>"
method="post" name="form1" id="form1" onsubmit="return Validate();">
...
<input type="submit" value="REGISTER" name="submit" />
</form>
Hey if you are sending a value as a part of the URL then you should have a container to grab it..use the php $_GET[] to grab that value..a bit of googling about php forms will help you rather than giving you the code.
http://www.w3schools.com/php/php_forms.asp Read from this link and keep coding!!
You need to add a hidden field to your form on ApplicationRegister.php that includes the 'plan' query parameter. The following HTML should sit within the form:
<input type="hidden" name="plan" value="<?php echo isset($_GET['plan']) ? $_GET['plan'] : 'trial'; ?>" />
The code sets the default value to be 'trial', should they visit this page without gone via the previous page.
Then you can handle the form data as you usual in 'emailconfirmation.php'. You can do something like:
if (isset($_POST))
{
$post_Plan = isset($_POST['plan']) ? $_POST['plan'] : null;
// etc ...
} else {
// redirect back
}

Categories