paulonline2501 Posted September 14, 2012 Share Posted September 14, 2012 (edited) hi, should be a straight forwrd answer for this one.is it possible to post twice to the same page? eg: you want the person to select an item from a drop down list, click a button to submit their choose (post #1), and then do something else like update the details of the item and then submit again (post #2). i mean i could go to a different page with the post#1 id after the first post, but i was wondering if i could do it all on the same page? i've had a stab at doing this and the code is below but when i click the 2nd post button it resets the whole page. ive got a sneaky recolection that this normal as this isnt possible but cant quite remember. any help would be great. CODE: <?phpif (isset($_POST['post1'])){echo"Form 1 has been submitted.";/**********post 2*******************************/ if (isset($_POST['post2'])) { echo"Form 2 has been submitted."; } else { //render form 2 ?> <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="form2"><fieldset> <table id="site-form"> <tr> <td class="one_of_three"> </td> <td class="two_of_three"><input name="post2" id="post2" type="submit" value="Click Me (2)"/> <a href="">Cancel</a>.</td> <td> </td> </tr> </table> </fieldset></form> <?php }/********** end post 2*******************************/}else {//render form 1?><form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="form1"><fieldset><table id="site-form"><tr> <td class="one_of_three"> </td> <td class="two_of_three"><input name="post1" id="post1" type="submit" value="Click Me (1)"/> <a href="">Cancel</a>.</td> <td> </td></tr></table></fieldset></form><?php}?> if you want to see whats happening its here:http://paulyouthed.c...p-two-posts.php Edited September 14, 2012 by as_bold_as_love Link to comment Share on other sites More sharing options...
niche Posted September 14, 2012 Share Posted September 14, 2012 (edited) You'd need javascript for that probably in connection with an ajax call. http://www.w3schools.com/php/php_ajax_intro.asp Edited September 14, 2012 by niche Link to comment Share on other sites More sharing options...
paulonline2501 Posted September 14, 2012 Author Share Posted September 14, 2012 ....ok, thanks. i think i'll just post to another page and have the 2nd button on the 2nd page. this would keep it on the server. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 14, 2012 Share Posted September 14, 2012 You can chain as many forms as you want. The reason your code shows form 1 again after submitting form 2 is because the first if statement where you're checking if $_POST['post1'] exists fails, form 2 does not submit an item called post1. Your first if statement should either check if either post1 or post2 are set, or give both forms the same name and give them different values. You can give them the same input name, like "form_name", and give it values like "form1", "form2", etc for the different forms. Then if you check if $_POST['form_name'] is set it will be set regardless of which form was submitted and you can check the value of $_POST['form_name'] to figure out which of the forms was submitted. Link to comment Share on other sites More sharing options...
kanchatchai Posted September 15, 2012 Share Posted September 15, 2012 <?php if (isset($_POST['post2'])) { echo"Form 2 has been submitted."; }else{if (isset($_POST['post1'])){echo"Form 1 has been submitted.";/**********post 2*******************************/ //render form 2 ?> <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="form2"><fieldset> <table id="site-form"> <tr> <td class="one_of_three"> </td> <td class="two_of_three"><input name="post2" id="post2" type="submit" value="Click Me (2)"/> <a href="">Cancel</a>.</td> <td> </td> </tr> </table> </fieldset></form> <?php/********** end post 2*******************************/}else{//render form 1?><form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="form1"><fieldset><table id="site-form"><tr> <td class="one_of_three"> </td> <td class="two_of_three"><input name="post1" id="post1" type="submit" value="Click Me (1)"/> <a href="">Cancel</a>.</td> <td> </td></tr></table></fieldset></form><?php}}// if (isset($_POST['post2'])) Link to comment Share on other sites More sharing options...
kanchatchai Posted September 15, 2012 Share Posted September 15, 2012 You'd need javascript for that probably in connection with an ajax call. http://www.w3schools..._ajax_intro.asp That great idia.That New knowledge. I wana to learn Thank....mmmmmmm..for as_bold_as_love reson i think canuse HttPRequest.open('POST',url,true); if possible on ajx code Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now