Reputation: 1897
I have one form which goes to another page and does some database operations.
<form id="form1" method="post" action="goes_to_page1.php" onsubmit="return checkformvalidation();">
<input type="text" id="field1" name="field1" onblur="checkvalue(this.value)">
<input type="text" id="field2" name="field2">
<button type="submit" id="butnid" >Go to page 1</button>
<form>
<script>
function checkvalue(val)
{
if(val==10)
{
document.getElementById("butnid").innerHTML = "Go to page 2";
}
<script>
So my form goes to goes_to_page1.php and does some database operations. But I have called a function on onblur property of field1. So if the value of the field1 is 10, button's label changes to go to page 2. And if the value is 10, I want my page to redirect to goes_to_page2.php and do some other operation. Is it even possible to do so based on the text of a button?
goes_to_page1.php
<?php
$f1=$_POST['field1'];
$f2=$_POST['field2'];
// submit to table1 in database
?>
goes_to_page2.php
<?php
$f1=$_POST['field1'];
$f2=$_POST['field2'];
// do some other operation in database
?>
Upvotes: 2
Views: 76
Reputation: 1327
this is the page1..
$GLOBALS['f1']=$_POST['f1'];
$_GLOBALS['f2']=$_POST['f2'];
if($f1==10)
{
header("location:goes_to_page2.php");
exit;
}
and in page 2
$f1= $GLOBALS['f1'];
$f2=$GLOBALS['f2'];
now the value of form is in the variable of page2..
is this the right answer?
Upvotes: 2
Reputation: 1327
if ($f1==10) {
header("location:goes_to_page2.php");
exit;
}
did you mean this?
Upvotes: 0
Reputation: 20753
Yes, you can change the form action dynamically. Just like this-
if this
document.<form-name>.action = "goes_to_page1.php";
else if that
document.<form-name>.action = "goes_to_page2.php";
Upvotes: 0