kuclu
asked on
make form ACTION a variable
I have a multipage form, where the user progresses from one page to another in a prefixed order. Now i want to give the user the option to choose where he wants to proceed, i.e. I am trying to make the value of the <FORM ACTION =""> elements to be different.
Example:
If user selects "GO to form A" from a pulldown menu,
then <FORM ACTION="formA.php">
If user selects "GO to form B" from a pulldown menu,
then <FORM ACTION="formB.php">
Is this possible?
This is what my multipage form looks like. I have a fieldforwarder so that choices selected are 'memorized' from one page to another, until the final page is submitted to a database...
========================== ========== ========== ========== =========
<?php
include ('fieldforwarder.php');
?>
<html>
<HEAD></HEAD>
<BODY>
<FORM method="post" action="form2.php" name="form1">
<INPUT TYPE="checkbox" NAME="cb1" VALUE="a">A</td>
<INPUT TYPE="checkbox" NAME="cb2" VALUE="b">B</td>
<INPUT TYPE="checkbox" NAME="cb3" VALUE="c">C</td>
<INPUT TYPE="checkbox" NAME="cb4" VALUE="d">D</td>
<?php echo field_forwarder(); ?>
<p><input type="submit" name="submit2" value="Proceed >>">
</FORM>
</BODY>
</HTML>
Example:
If user selects "GO to form A" from a pulldown menu,
then <FORM ACTION="formA.php">
If user selects "GO to form B" from a pulldown menu,
then <FORM ACTION="formB.php">
Is this possible?
This is what my multipage form looks like. I have a fieldforwarder so that choices selected are 'memorized' from one page to another, until the final page is submitted to a database...
==========================
<?php
include ('fieldforwarder.php');
?>
<html>
<HEAD></HEAD>
<BODY>
<FORM method="post" action="form2.php" name="form1">
<INPUT TYPE="checkbox" NAME="cb1" VALUE="a">A</td>
<INPUT TYPE="checkbox" NAME="cb2" VALUE="b">B</td>
<INPUT TYPE="checkbox" NAME="cb3" VALUE="c">C</td>
<INPUT TYPE="checkbox" NAME="cb4" VALUE="d">D</td>
<?php echo field_forwarder(); ?>
<p><input type="submit" name="submit2" value="Proceed >>">
</FORM>
</BODY>
</HTML>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What I would do is send the user to the next page and there you use a switch statement to display the form he selected in the first place.
switch($form)
{
case 'a':
display form a
break;
case 'b':
display form b
break;
}
and so on
switch($form)
{
case 'a':
display form a
break;
case 'b':
display form b
break;
}
and so on
Using your code if you click a checkbox it will use that as the action:
<html>
<head>
<script language="JavaScript">
<!--//
function changeAction(yourvalue) {
var myform = document.getElementById('m yform');
myform.action=yourvalue;// myfield.va lue;
}
//--></script>
</head>
<body>
<FORM method="post" id="myform" action="form2.php" name="form1">
<INPUT TYPE="checkbox" NAME="cb1" VALUE="a" onclick="changeAction('cb1 ');">A</td >
<INPUT TYPE="checkbox" NAME="cb2" VALUE="b" onclick="changeAction('cb2 ');">B</td >
<INPUT TYPE="checkbox" NAME="cb3" VALUE="c" onclick="changeAction('cb3 ');">C</td >
<INPUT TYPE="checkbox" NAME="cb4" VALUE="d" onclick="changeAction('cb4 ');">D</td >
<p><input type="submit" name="submit2" value="Proceed">
</FORM>
</body>
</html>
<html>
<head>
<script language="JavaScript">
<!--//
function changeAction(yourvalue) {
var myform = document.getElementById('m
myform.action=yourvalue;//
}
//--></script>
</head>
<body>
<FORM method="post" id="myform" action="form2.php" name="form1">
<INPUT TYPE="checkbox" NAME="cb1" VALUE="a" onclick="changeAction('cb1
<INPUT TYPE="checkbox" NAME="cb2" VALUE="b" onclick="changeAction('cb2
<INPUT TYPE="checkbox" NAME="cb3" VALUE="c" onclick="changeAction('cb3
<INPUT TYPE="checkbox" NAME="cb4" VALUE="d" onclick="changeAction('cb4
<p><input type="submit" name="submit2" value="Proceed">
</FORM>
</body>
</html>
Copy and paste code below.
if you select a from the select box you go to forma.php
if you select b from the select box you go to formb.php
<html>
<head>
<script language="JavaScript">
<!--//
function changeAction() {
var myform = document.getElementById('m yform');
var myfield = document.getElementById('m yfield');
myform.action='form'+myfie ld.value+' .php';
}
//--></script>
</head>
<body>
<FORM method="post" id="myform" action="form2.php" name="form1">
<select id="myfield" onchange="changeAction();" >
<option value="a">Go A</option>
<option value="b">Go B</option>
</select>
<INPUT TYPE="checkbox" NAME="cb1" VALUE="a" >A</td>
<INPUT TYPE="checkbox" NAME="cb2" VALUE="b" >B</td>
<INPUT TYPE="checkbox" NAME="cb3" VALUE="c" >C</td>
<INPUT TYPE="checkbox" NAME="cb4" VALUE="d" >D</td>
<p><input type="submit" name="submit2" value="Proceed">
</FORM>
</body>
</html>
if you select a from the select box you go to forma.php
if you select b from the select box you go to formb.php
<html>
<head>
<script language="JavaScript">
<!--//
function changeAction() {
var myform = document.getElementById('m
var myfield = document.getElementById('m
myform.action='form'+myfie
}
//--></script>
</head>
<body>
<FORM method="post" id="myform" action="form2.php" name="form1">
<select id="myfield" onchange="changeAction();"
<option value="a">Go A</option>
<option value="b">Go B</option>
</select>
<INPUT TYPE="checkbox" NAME="cb1" VALUE="a" >A</td>
<INPUT TYPE="checkbox" NAME="cb2" VALUE="b" >B</td>
<INPUT TYPE="checkbox" NAME="cb3" VALUE="c" >C</td>
<INPUT TYPE="checkbox" NAME="cb4" VALUE="d" >D</td>
<p><input type="submit" name="submit2" value="Proceed">
</FORM>
</body>
</html>
onchange="form1.action=thi
if you are using checkboxes just use the onClick event:
onClick="form1.action='a';