EchoFool Posted February 10, 2008 Share Posted February 10, 2008 I have a form with 2 options, one is update, and one is report. Now if the button to report is pressed the action of the form needs to go to report page. Where as if the update button is pressed the action should not header to a different page for it should just stay on the current page and "update" the information. How ever i do not know how this can be done. If I put an action in the form entities then it will always header away so i need it only go to the action when one of the buttons is pressed. One of the unfortionutly things is i cannot use 2 separate forms as i have just found out before they are post $_POST-ing the same text area. And if i put the text area in both forms it will display on the web page twice which is not good . The only idea i can think of but i do not know if it will work is something like this: |<form1 - headers to filereport.php> | |<form2 - stays on the same page but just "refreshes" to allow the script to update> | | <button2> | |</form2> | |<button1> | |</form1> Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted February 10, 2008 Share Posted February 10, 2008 It's pretty simple really, try this: File Name: index.php <?php if(isset($_POST['report'])) { header("Location: report.php"); // Put your location file here } else if (isset($_POST['update'])) { // Put your MySQL update query here or whatever you're wanting to update } ?> <form action="index.php" method="post"> <!-- Form elements here --> <input type="submit" name="report"> <input type="submit" name="update"> </form> I think that's pretty much what you're trying to do. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 10, 2008 Author Share Posted February 10, 2008 Kinda except i can't use headers. Because the script is surrounded by 2 css files: include css1.css //script include css2.css This is because my site's content is always in the center div so i put the left right header and footer in my includes. And so as you would expect when i use a header i get the output already started. It is a pain! Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted February 10, 2008 Share Posted February 10, 2008 How about this... <?php if(isset($_POST['report'])) { echo "<meta http-equiv=\"REFRESH\" content=\"0;url=report.php\">"; // Put your location file here exit; } else if (isset($_POST['update'])) { // Put your MySQL update query here or whatever you're wanting to update } ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 10, 2008 Share Posted February 10, 2008 First, you really shouldn't separate CSS blocks with code. Second, you can not put one form inside another. Learn proper HTML before attempting to use PHP and you will find that you will write better PHP. You don't need to go to different pages for this: <?php if (isset($_POST['submit'])) { switch ($_POST['submit']) { case 'Update': // // update code here // break; case 'Report': // // report code here // break; } } ?> <html> <head> CSS links here </head> <body> <form method="post"> ... form stuff ... <input type="submit" name="submit" value="Update"> <input type="submit" name="submit" value="Report"> </form> </body> </html> Ken Quote Link to comment Share on other sites More sharing options...
Rohan Shenoy Posted February 10, 2008 Share Posted February 10, 2008 May be you should use some javascript to change the action attribute of the form on onlcick on radio button! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.