I had two forms
login form
Registration form
login form has the username and password fields and registration form consists controls for registration like username, city, country, etc.,
Also, I have some hidden controls like
<input type="hidden" name="ctrl1" />
<input type="hidden" name="ctrl2" />
<input type="hidden" name="ctrl3" />
<input type="hidden" name="ctrl4" />
Which is dynamically generated using PHP Code.
What I want is, When the user click login form's submit or the registration form's submit, the hidden controls data should also be Posted.
Insert the hidden inputs into both forms when you generate the page:
<form id='form1' action='' method='post'>
<input type='hidden' name='h1' value='v1' />
<input type='hidden' name='h2' value='v2' />
<input type='hidden' name='h3' value='v3' />
<input type='submit' name='submit' value='Submit Form 1' />
</form>
<form id='form2' action='' method='post'>
<input type='hidden' name='h1' value='v1' />
<input type='hidden' name='h2' value='v2' />
<input type='hidden' name='h3' value='v3' />
<input type='submit' name='submit' value='Submit Form 2' />
</form>
Use this example, definitely it will help you.
<SCRIPT LANGUAGE="JavaScript">
function runscript()
{
document.form1.submit();
document.form2.submit();
}
</SCRIPT>
<BODY>
<FORM METHOD=POST ACTION="http://localhost/login.php" NAME="form1">
<INPUT TYPE="text" NAME="text1">
</FORM>
<FORM METHOD=POST ACTION="http://localhost/register.php" NAME="form2">
<INPUT TYPE="text" NAME="text2">
</FORM>
<INPUT TYPE="button" value="Submit" onClick="runscript()">
</BODY>
Use jQuery's serialize on one of the forms.
Related
I have a form, something like this:
<form action='index.php?page=search&filter=1'>
<input type='text' name='ID'>
<input type='text' name='number'>
<input type='submit'>
</form>
If I submit form, it will go to page:
index.php?ID=value1&number=value2
I would like to have
index.php?page=search&filter=1&ID=value1&number=value2
How can I append extra fields to url ?
Thank you for help.
you should put these values in hidden inputs:
<form action='index.php'>
<input type='hidden' name='page' value='search'>
<input type='hidden' name='filter' value='1'>
<input type='text' name='ID'>
<input type='text' name='number'>
<input type='submit'>
</form>
You can submit additional GET value as a hidden field value in the form which will be submit along with form submission.
<form action="index.php" method="get">
<input type='text' name='ID'>
<input type='text' name='number'>
<input type='hidden' name='page' value='search'>
<input type='hidden' name='filter' value='1'>
<input type='submit'>
</form>
Use hidden fields with your form and you will get exact url you want.
Try below code :
<form action="index.php" method="get">
<input type='hidden' name='page' value='search'>
<input type='hidden' name='filter' value='1'>
<input type='text' name='ID'>
<input type='text' name='number'>
<input type='submit'>
</form>
Try using some hidden input fields and use get method in form submitting.
Try this:
<form action="index.php" method="GET">
<input type='hidden' name='page' value='search' />
<input type='hidden' name='filter' value='1' />
<input type='text' name='ID' value='value1' />
<input type='text' name='number' value='value2' />
<input type='submit' value='Submit' />
</form>
i have two file and two forms:
file 1:
<form name="name1" action="form2.php" method="post">
<input <? $_session['define'] = 'value1' ?> type="submit" ...>
</form>
<form name="name2" action="form2.php" method="post">
<input <? $_session['define'] = 'value2' ?> type="submit" ...>
</form>
As you see i have two forms and two different submit buttons but when i press each of them, the second value (the last) set to the $_session['define'] and in the second form i always have 'value2'.
You must post the data to PHP:
<form name="name1" action="form2.php" method="post">
<input name='v1' value='1' type="submit" />
</form>
<form name="name2" action="form2.php" method="post">
<input name='v2' value='2' type="submit" />
</form>
In form2.php:
<?php
session_start();
$_SESSION['value1'] = isset($_POST['v1'])?$_POST['v1']:0;
$_SESSION['value2'] = isset($_POST['v2'])?$_POST['v2']:0;
?>
Personally, I would make it one form and use JQuery/AJAX to POST the values.
<form id="selectForm" name="name1" action="form2.php" method="post">
<input id="v1" name='v1' value='1' type="submit" />
<input id="v2" name='v2' value='2' type="submit" />
</form>
<script>
// Requires JQuery
$("#selectForm input[id^='v']").click(function(e){
e.preventDefault();
$.post(form2.php, { $(this).attr("name"): $(this).attr("value") }, function(){ alert("Selection Saved.) });
});
</script>
Here is the form
form.php
<form name='formONE' action='form.php'>
<select name='multiselect[]' method='post'>
<option name='1'>one</option>
<option name='2'>tow</option>
<option name='3'>three</option>
<option name='4'>four</option>
</select>
<input type='submit' value='choosed' />
</form>
<form name='formTOW' action='form.php'>
<input type='text' name='text1' />
<input type='text' name='text2' />
<input type='text' name='text3' />
<input type='text' name='text4' />
<input type='text' name='selectedone' value='
<? foreach($_post['multiselect'] as $slct){print ", $slct";}' />
<input type='submit' value='save'/>
</form>
Here, on fromONE the user will select the options(some of option will be selected means selective) after the selection and submit the data will be passed to the form named formTOW input name = selectedone and after i submit formTOW data will pass to database.
but now here on formTOW if i input some value but in last if i select some data from formONE and submit the data of formTOW will be ears
here i want the formONE sumbit to do not make any change or effect on formTOW
regards
You can't put a form inside a form, this is just not allowed in HTML.
If you don't want to use javascript you can use the forms side by side. But it is just as easy to put everything in one form. Just ignore what you don't need when you evaluate the form values.
<form name='form' action='form.php'>
<input type='text' name='text1' />
<input type='text' name='text2' />
<input type='text' name='text3' />
<input type='text' name='text4' />
<input type='submit' value='save'/>
</form>
<form name='form1' action='form.php'>
<select name='multiselect[]' method='post'>
<option name='1'>one</option>
<option name='2'>tow</option>
<option name='3'>three</option>
<option name='4'>four</option>
</select>
<input type='text' name='selectedone' value='
<? echo implode(", ", $_POST['multiselect']); ?> />
<input type='submit' value='TransferToTnputTextFromSelect'/>
</form>
I have a form where I would like to use _POST data to submit check box values. My problem is there are already post values in my current page. When I submit the form it is returning the current post values instead of the ones I want, which gives me the Notice: Undefined index message.
Basically this form is to compare selected products, but in the current post values it has the product information along with order by values. Is there a way to just submit my new form's information on its own?
Thank you
EDIT
Well, here's the thing about my code, I am using a shopping cart called Virtuemart. I've added the code below minus all the other stuff which don't effect the form.
Product File
// Code here for Template file for individual items in category
//creating checkbox for comparison form
echo "<input type =\"checkbox\" name=\"fruit[]\" value=\"".$product_sku."\" />
<label for=\"".$product_name."\"> ".$product_name."</label>";
Category File
//all other forms on this page
<form action="items/index.php" method="get" name="results" target="_blank">
<input class="inputbox" name="search" id="item-search" type="text" value="Search"></td><td>
<input type="image" class="sub-button" src="/search.png" alt="submit" name="submit" value="search">
</form>
<form action="index.php" method="get" name="order">
Sort by:
<select class="inputbox" name="orderby" onchange="order.submit()">
<option value="product_list" >Select</option>
<option value="product_name" selected="selected">Product Name</option>
<option value="product_price" >Price</option>
<option value="product_cdate" >Latest Products</option>
</select>
<script type="text/javascript">//<![CDATA[
document.write(' <input type="hidden" name="DescOrderBy" value="ASC" /><img src="images/sort_asc.png" border="0" alt="Ascending order" title="Ascending order" width="12" height="12" />');
//]]></script>
<noscript>
<select class="inputbox" name="DescOrderBy">
<option value="DESC">Descending order</option>
<option selected="selected" value="ASC">Ascending order</option>
</select>
<input class="button" type="submit" value="Submit" />
</noscript>
<input type="hidden" name="Itemid" value="89" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="page" value="shop.browse" />
<input type="hidden" name="category_id" value="0" />
<input type="hidden" name="manufacturer_id" value="0" />
<input type="hidden" name="keyword" value="" />
<input type="hidden" name="keyword1" value="" />
<input type="hidden" name="keyword2" value="" />
<div id='limitbox'> Display #
<select class="inputbox-reg" name="limit" size="1" onchange="this.form.submit();">
<option value="6" >6</option>
<option value="18" >18</option>
<option value="30" >30</option>
</select>
<input type="hidden" name="limitstart" value="0" /></div> <noscript><input type="submit" value="Submit" /></noscript>
<!-- PAGE NAVIGATION AT THE TOP <br/>
<div style="text-align:center;"> </div>
-->
</form>
// all other forms end
Form I want to pass values from
echo"<form method=\"POST\" name=\"compare\" id=\"compare\" action=\"http://localhost/comparepage/\">";
//TEMPLATE FILE HERE THAT GENERATE PRODUCTS FROM PRODUCT FILE CODE ABOVE.
//Basically it has foreach statements to generate all products
echo "<input type=\"submit\" name=\"submit\" value=\"Compare\" onClick=\"document.compare.submit()\" >";
echo "</form>";
I've changed POST to GET just to get the values that are being passed and in the next page I see a bunch of values in the url.
Try putting the fields of the second form within separate <form> tags
Form 1:
<form method='post' action='/process.php'>
<input name='town' type='text'/>
<input name='country' type='text'/>
<input type='submit'/>
</form>
Form 2:
<form method='post' action='/process.php'>
<input name='gender' type='text'/>
<input name='state' type='text'/>
<input type='submit'/>
</form>
If you submit form 1, $_POST will contain town, country
If you submit form 2, $_POST will contain gender & state
As suggested, some code and more details would be helpful. But if you have multiple form fields on the same page, and depending on the action, you want to submit different sets of those fields, then just wrap them in different <form></form> elements. A POST submit only submits the form fields contained with that particular block.
So you could have:
<form name='form1' method='POST' action='#'>
<input type='hidden' name='field1' value='true' />
<input type='submit' name='submit' value='Submit' />
</form>
<form name='form2' method='POST' action='#'>
<input type='hidden' name='field1' value='false' />
<input type='submit' name='submit' value='Submit' />
</form>
If the first submit button is clicked, $_POST['field1'] = 'true', else = 'false'
I have two forms, first form contains the textbox and second form contains a button. I want to validate the textbox using the button (jquery or javascript) :
<form name="contactus" method="post">
<input name="txtFirstname" id="Firstname" type="text" class="field" Value="First name*" style="width:300px" />
</form>
<form name="frm1" action="sendemail.php" method="post">
<input id="send" type="image" src="images/sub.png" alt="Submit" style="float:right" />
</form>
how would i be able to do this when my textbox is not on 'frm1'
Here are examples of the two approaches I suggested in the comments above:
1) Using Javascript to alter the action attribute of the form depending on the button that was clicked:
<form id='the_form' action='' method='post'>
<input type='text' name='text_input' />
<input type='button' id='button_1' value='Button 1' />
<input type='button' id='button_2' value='Button 2' />
</form>
<script type='text/javascript'>
var theForm = document.getElementById('the_form');
$('#button_1').click(function() {
theForm.action = 'script1.php';
theForm.submit();
});
$('#button_2').click(function() {
theForm.action = 'script2.php';
theForm.submit();
});
</script>
2) Holding all the submit handler code in a single script (recommended):
HTML:
<form id='the_form' action='script.php' method='post'>
<input type='text' name='text_input' />
<input type='submit' name='submit_1' value='Submit' />
<input type='submit' name='submit_2' value='Submit' />
</form>
PHP:
<?php
if (isset($_POST['submit_1'])) {
echo 'You clicked button 1';
} else if (isset($_POST['submit_2'])) {
echo 'You clicked button 2';
}
Did you try this?
$('#send').click(function(){
var textVal = $('#Firstname').val();
//your validation code goes here
});