JakeJ Posted May 16, 2010 Share Posted May 16, 2010 This problem is absolutely KILLING ME. I have index.php and it's a form with action=<?php echo $_SERVER['PHP_SELF']; ?> I want to do everything inside of index.php using includes. I have some code that determines that name of the include that goes in the body of the page. This works fine when I first load the page since it's either looking for the results of a variable or goes to a static page name. The include that goes in the body of the page, contains the inputs for the form. When I submit the form, I want it to do some processing and error checking and either return the errors (which works just fine) or redirect back to index.php but with a different include in the body. The example that I've got forces me to submit twice in order for the redirect to happen if I do any conditional checking and assign the next page based on that. I thought about posting my sample code that isn't working but I'm so turned around in my head now, I don't know which way is up. Starting with a fresh example from someone else is bound to give me some perspective on the matter. So how would you do this? Thanks! Link to comment https://forums.phpfreaks.com/topic/201939-_serverphp_self-and-dynamic-includes/ Share on other sites More sharing options...
siric Posted May 16, 2010 Share Posted May 16, 2010 Would you mind posting the code, so that we can get a better idea of what you are attempting? Link to comment https://forums.phpfreaks.com/topic/201939-_serverphp_self-and-dynamic-includes/#findComment-1059080 Share on other sites More sharing options...
JakeJ Posted May 16, 2010 Author Share Posted May 16, 2010 Here's my code: What happens is, when index.php loads and $_SESSION['submit'] is not set, it loads test.php. That works great. When I click the button on the form, the code in test.php checks to see if submit is set and sets $_SESSION['submit'] and sets that to 'test2.php'. But then when the form reloads, I have to click submit AGAIN in order for it to actually go to test2.php. I don't know why. Since $_SESSION['submit'] has been set, why doesn't my logic at the top of index.php read it and set $body_include to the right form and load it appropriately? <?php session_start(); $header_include = './includes/mainstyle.php'; if(isset($_SESSION['submit'])) { $body_include = $_SESSION['submit']; } Else { $body_include = "test.php"; } include ($header_include); ?> </head> <body class="twoColFixLtHdr"> <FORM NAME = "MAINFORM" ACTION=<?php echo $_SERVER['PHP_SELF']; ?> METHOD=POST runat="vdaemon"> <!-- begin #header --> <?php include_once("/includes/incl_header2.php"); ?> <!-- end #header --> <!-- begin #sidebar --> <div id="sidebar1"> <?php include ("/includes/incl_sidebar.php"); ?> </div> <!-- end #sidebar --> <!-- end #sidebar1 --> <!-- begin #main content --> <div id="mainContent"> <?php echo $body_include; include($body_include); #$process =1; ?> </div> <!-- end #mainContent --> <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --> <br class="clearfloat" /> <div id="footer"> <p> </p> <!-- end #footer --></div> <!-- end #container --></div> </FORM> </body> </html> //test.php <?php Echo "Please log in<br> Username: <input type='text' name='username' value='' /><br /> Password: <input type='password' name='password' value='' /><br /><br /> Log In <INPUT ID='submit' NAME='submit' TYPE=IMAGE BORDER=0 SRC='../images/wiz_edit.png' VALUE='login'><p>"; If (isset($_POST['submit'])) { $_SESSION['submit'] = 'test2.php'; } ?> Link to comment https://forums.phpfreaks.com/topic/201939-_serverphp_self-and-dynamic-includes/#findComment-1059252 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.