Showing posts with label multiple forms on a single page. Show all posts
Showing posts with label multiple forms on a single page. Show all posts

Sunday, March 9, 2014

load dynamic forms based on drop down selected by user

hi,
well there are many ways of doing this. i have done it the following way:-
HTML
<div id="spc">
<select id="selectform" onChange="selfo();">
<option value="0">0</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>  
</select>
      <form id="abc" style="display:none">
      <input>
      </form>
      <form id="def" style="display:none">
      <input><input>
      </form>
      <form id="ghi" style="display:none">
      <input><input><input>
      </form>
      </div>

//javascript
    <script>
function selfo()
{
var a = document.getElementById("selectform").value;
if(a == 1){
document.getElementById("abc").style.display = "block";
document.getElementById("def").style.display = "none";
document.getElementById("ghi").style.display = "none";
}
else if(a == 2){
document.getElementById("def").style.display = "block";
document.getElementById("abc").style.display = "none";
document.getElementById("ghi").style.display = "none";
}
else if(a == 3){
document.getElementById("ghi").style.display = "block";
document.getElementById("abc").style.display = "none";
document.getElementById("def").style.display = "none";
}
else if(a == 0){
document.getElementById("spc").style.display = "none";
}
}
    </script>  
  

Thursday, December 8, 2011

how to use multiple forms on a single page

just name the submit button like this


1st form
<form action="abc.php" method="post"> 
<input type="text" name="abc">
<input type="submit" name="abc">
</form>
2nd form

<form action="abc.php" method="post"> 
<input type="text" name="def">
<input type="submit" name="xyz">
</form>
process the firm results
<?php
if(count($_POST)){
if (!empty($_POST["abc"])){
run your code here for 1st form
}
elseif(!empty($_POST["xyz"])){
run your code here for 2nd form
}
}
?>

you can place as many forms on a single page. As long as the submit name is different, only 1 form will be processed at a time.