jmrozi1 Posted April 21, 2009 Share Posted April 21, 2009 Take the following code: //index.shtml <html> <body> <!--#if expr=”$QUERY_STRING = /main=action/” --> <!--#include virtual=”action.php” --> <!--#else --> <!--#include virtual=”form.html” --> <!--#endif --> </body> </html> //form.html <form action=”index.shtml?main=action” method=”post”> Enter name: <input name=”username” /> <br />Submit <input type=”submit” /> </form> //action.php <?php if(array_key_exists(“username”, $_POST){ echo “Name entered: “ . $_POST[“username”] . “<br />”; } else{ echo count($_POST); } ?> My goal is to get the action page to output the “username” input upon submit, but the actual output will be “0”. If I didn't need to use SSI, the most obvious solution would be to make the form pass directly to the action.php page or to use php rather than SSI for the index page. However, I'd like to use SSI to include a standard header and footer that display Apache environment variables, so I'm looking for a way for index.shtml to pass form variables to an included php page, or at least to know whether or not it's possible. Thanks! Link to comment https://forums.phpfreaks.com/topic/155033-how-can-you-inherit-post-variables/ Share on other sites More sharing options...
adx Posted April 21, 2009 Share Posted April 21, 2009 I might have misunderstood but if you're getting 0 as a result and not the username, you could use this instead. <?php if(isset($_POST['username'])) { echo “Name entered: “ . $_POST['username'] . “<br />”; } else{ echo "Hey! You're nameless!"; } ?> Link to comment https://forums.phpfreaks.com/topic/155033-how-can-you-inherit-post-variables/#findComment-815496 Share on other sites More sharing options...
Yesideez Posted April 21, 2009 Share Posted April 21, 2009 Can you not write the includes in PHP then just use include() to call them in? If you can stick to one way of doing things it makes it so much easier! Link to comment https://forums.phpfreaks.com/topic/155033-how-can-you-inherit-post-variables/#findComment-815515 Share on other sites More sharing options...
jmrozi1 Posted April 21, 2009 Author Share Posted April 21, 2009 In this case, the code will always print "Hey! You're nameless!", regardless of the name entered. This is because the form variables, which are being passed to the page "index.shtml?main=action", aren't being inherited by the included file "action.php". I've been looking further into the problem and found that environment variables are inherited. For example, if I create an apache variable in index.shtml: <!--#set var="testVariable" value="test" -->, then I'll be able to recall this variable in "action.php" as $_SERVER["testVariable"]. This can be used to pass GET variables: <!--#set var="getVariables" value="$QUERY_STRING" -->, which could then be used in "action.php" as $_SERVER["getVariables"]. However, I'm not sure how to apply this approach to the POST method for passing variables. Link to comment https://forums.phpfreaks.com/topic/155033-how-can-you-inherit-post-variables/#findComment-815525 Share on other sites More sharing options...
jmrozi1 Posted April 21, 2009 Author Share Posted April 21, 2009 Can you not write the includes in PHP then just use include() to call them in? If you can stick to one way of doing things it makes it so much easier! For this to work, I'd have to rename the file "index.shtml" to "index.php", which would mean that the SSI directives wouldn't work (I could configure the server to parse .php files for SSI, but this is generally bad practice). I'll probably end up having to do it this way, but I was hoping to avoid it considering the amount of code I'd have to rewrite. Link to comment https://forums.phpfreaks.com/topic/155033-how-can-you-inherit-post-variables/#findComment-815532 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.