Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass form value to a URL within the same form? 1

Status
Not open for further replies.

misslois74

Programmer
Sep 27, 2008
63
PH
Hello,

Im working on this website which has a form on it and upon clicking the submit button it should go to an autoresponder system(this is working fine) now the problem is i would like to use the same form to collect the information and store it to the database, its like having multiple actions on one form which im not sure how to go about it, Im looking at another solution wherein the form passes a hidden element which has the value of the URL where the page will be redirected after the autoresponder process the form, now my question is how will I pass my form value to that URL so that when it is redirected to that page i would be able to collect the data and store it to the database, i've been going around to solve this issue....hope you could help me...Thanks in advance.
 
I agree with feherke. Your redirecction logic should be done serverside. That makes it easy to save the data into the DD, and then redirect to the autoresponder only the information you may want included in the response.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
can anybody check on this script it seems that the javascript is not working:

<?php
if(isset($_POST['register']))
{
//header("Location: $_POST[redirect]");
$text1 = $_POST['text1'];
$text2 = $_POST['text2'];
echo "from the main source: <br>";
echo "text 1:" . $text1 . "<br>text 2:" . $text2;
}
?>
<form method="post" action="check.php" name="Form1" id="Form1" target="_top">
Text 1:<input type="text" name="text1" id="text1"/>
Text 2:<input type="text" name="text2" id="text2"/>
<input type="submit" value="submit" name="register" onclick="all_fields(); document.Form2.value1.value = document.Form1.text1.value; document.Form2.value2.value = document.Form1.text2.value; document.Form2.submit(); document.Form1.submit();">
</form>

<form method="post" action="sample2.php" name="Form2" id="Form2" target="iframe" style="display:none">
<input type="hidden" name="value1" />
<input type="hidden" name="value2" />
</form>

<iframe name="iframe" style="display:none">

</iframe>


the second form contains the value that i would like to pass to the other page, what my javascript does is to capture the value entered on the first form and store it as the value in my second form....Am I on the right track? but it seems my javascript is not working since my second form is not doing processing....
thanks

 
Hi

You can not submit two [tt]form[/tt]'s like that. It may seem to work in some circumstances, but is not correct and is not guaranteed to work.

If you not want to listen to our advice of solving this server-side, you could try two approaches :
[ul]
[li]Send the [tt]form[/tt]'s content to the first URL though AJAX, then submit the [tt]form[/tt] to the second URL.[/li]
[li]Submit the [tt]form[/tt] to the first URL, wait a dozen of seconds, then submit the [tt]form[/tt] to the second URL. Adjust the server-side script behind the first URL to return HTTP response code 204, No content.[/li]
[/ul]
Of course, the second may still fail. So try the first one.

Feherke.
 
or you can do this (this may be Feherke's 2nd suggestion):

Code:
<form action="process1.php" id="myform">
<input type="text" name="value1" />
<input type="text" name="value2" />
<input type="submit" />
</form>

Code:
<?php
$text1 = $_POST["value1"];
$text2 = $_POST["value2"];
// do the processing
?>
<form action="process2.php" id="myform">
<input type="text" name="value1" value="<?php echo $text1 ?>"/>
<input type="text" name="value2" value="<?php echo $text1 ?>" />
</form>
<script language="javascript">
document.getElementById("myform").submit();
</script>

Code:
<?php
$text1 = $_POST["value1"];
$text2 = $_POST["value2"];
// do the processing
?>


^ haven't worked with PHP in a while, sorry if my syntax isn't quite exact, but you should get the point...



--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
Hi

vicvirk said:
this may be Feherke's 2nd suggestion
So I was unclear, as usually. My second suggestion was this :
HTML:
[b]<form[/b] [maroon]action[/maroon][teal]=[/teal][green][i]"process1.php"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"myform"[/i][/green] [maroon]onsubmit[/maroon][teal]=[/teal][green][i]"setTimeout(function(){with(document.getElementById('myform')){action='process2.php';submit()}},12*1000)"[/i][/green][b]>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text"[/i][/green] [maroon]name[/maroon][teal]=[/teal][green][i]"value1"[/i][/green] [b]/>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text"[/i][/green] [maroon]name[/maroon][teal]=[/teal][green][i]"value2"[/i][/green] [b]/>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"submit"[/i][/green] [b]/>[/b]
[b]</form>[/b]
Code:
[teal]<?php[/teal]
[COLOR=darkgoldenrod]header[/color][teal]([/teal][green][i]'HTTP/1.1 204 No Content'[/i][/green][teal]);[/teal]
[teal]?>[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top