Hi,
If I want script A to go to script B and send POST variables, it can be easy: just add an onclick=action='script B' on the submit button. But what if I have validations that I first want to perform in script A before posting to script B? This is what I first tried (and it did not work):
//Once click on ViewButton perform validations and then POST to script B
if (viewButton) {
if (!validateForm()) {
} else {
$myform = <script type=javascript>
$myform.= document.f1.action='scriptB'
$myform.= document.f1.submit()
$myform.= </<script>
echo $myform
}
}
.
.
$myform1.= <form name='f1' action='php_self' method='post' ...
.
.
$myform1.= <input type=textarea name=prm1 value=$prm1
$myform1.= <input type=textarea name=prm2 value=$prm2
//Note that the following does not have onclick=action='scriptB' because I want the validation
//to be performed in this script before going to the new script
$myform1.= <input type=submit name=ViewButton> View Button
.
.
echo $myform1
The part above in Bold did not work and I think because the client does not recognize form 'f1' (which was sent previously (line 'echo $myform1') , before the view button was clicked) and this led me to think that if one wants to send something like document.f1.submit() it should include the form tag and hidden elements that you want to send as POST.
So this led me to rewrite something like this:
if (viewButton) {
if (!validateForm()) {
} else {
submitForm(prm1, prm2 --- some parameters that are fields in form 'f1');
}
}
function submitForm(prm1, prm2) {
$myform2.= <form name='f2' action='scriptB.php' method='post' ...
$myform2.= <input type=hidden name=prm1 value=$prm1>
$myform2.= <input type=hidden name=prm2 value=$prm2>
$myform2.= <script type=javascript>
$myform2.= document.f2.submit()
$myform2.= </<script>
.
.
echo $myform2
}
This solution, although it works, seems peculiar to me because it means that if I want to first validate form f1 before submitting it I need to add form f2 with all the elements I want to POST.
I hope I am sounding clear.
I wonder if someone can help me see how I can do things better. I have a feeing I am missing something.
Thanks.