Omzy Posted September 8, 2009 Share Posted September 8, 2009 I got an application which has two states, as follows: State 1) index.php?action=add if((isset($_POST['submit'])) || (isset($_GET['action']) && $_GET['action']=='add')) On this page there is a form, when you submit the form it goes back to this state and displays a "confirmation" message. if(isset($_POST['submit']) && empty($errors)) { //run the query //display the message } If there was an error in the form it re-displays the form with an error message. State 2) index.php?action=display if(isset($_GET['action']) && $_GET['action']=='display') On this page the added entries are displayed I want to change the functionality now so that it displays state 2 when an entry has been successfully added, with a "confirmation" message. If there was an error in the submitted data it re-displays the previous form. Can this be acheived without using a header() function? Quote Link to comment https://forums.phpfreaks.com/topic/173610-form-logic-required/ Share on other sites More sharing options...
sKunKbad Posted September 8, 2009 Share Posted September 8, 2009 I think a more common way to achieve this would be to have the form post back to the file it resides in. You can check for form submission, validate, and then display your confirmation message/error message all within one file. <?php If($_POST['submit']){ //validate //show confirmation or error } if(!isset($_POST['submit']) OR $error == 1){ //show form } Quote Link to comment https://forums.phpfreaks.com/topic/173610-form-logic-required/#findComment-915125 Share on other sites More sharing options...
Omzy Posted September 8, 2009 Author Share Posted September 8, 2009 That's what it's already doing. Read the post properly. Quote Link to comment https://forums.phpfreaks.com/topic/173610-form-logic-required/#findComment-915127 Share on other sites More sharing options...
sKunKbad Posted September 9, 2009 Share Posted September 9, 2009 By an entry being "successfully added", do you mean to a database? If that is the case, simply check to see if the insert was successful. I see no reason to use a redirect at all. Show more code if you need to. This is the way I would do the update, but it is OOP. Adapt as needed <?php if($insert = $this->db->insert($table_name, $data)) { // congradulations, you did it } else { // please try again } Quote Link to comment https://forums.phpfreaks.com/topic/173610-form-logic-required/#findComment-915176 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.