w4seem Posted April 11, 2007 Share Posted April 11, 2007 ok i guess theres a quick answer to this one hopefully, i have a search field on a .php page. i want to return the results on the same page i.e i dont want the action to point to test2.php but test.php which is were my search filed is sitting at the moment. how do i do this? i got this on my first page: <form method="post" action="test2.php"> Name: <input type="text" size="10" maxlength="40" name="name"> <br /> <input type="submit" value="Send"> </form> and this on the second: <?php $name = $_POST['name']; if ($name=="Friday") echo "Have a nice weekend!"; elseif ($name=="Saturday") echo "Tomorrow is Sunday!"; else echo "Please enter Friday or Saturday"; ?> thanks Quote Link to comment Share on other sites More sharing options...
rpadilla Posted April 11, 2007 Share Posted April 11, 2007 include a hidden input tag inside your form <input type="hidden" name="action" value="submitted"> <? $action = $_POST['action']; if ($action == 'submitted') { //your codes here... } ?> cheers Quote Link to comment Share on other sites More sharing options...
w4seem Posted April 11, 2007 Author Share Posted April 11, 2007 do i change: <form method="post" action="test2.php"> and direct it to the same page and then have the hidden tag? does the hidden tag replace my submit tag or is it in additon to it? could you explain the hidden tag a little please so i understand it better. ill google it also and see what i can find. thanks Quote Link to comment Share on other sites More sharing options...
rpadilla Posted April 11, 2007 Share Posted April 11, 2007 here you go file test.php <?php $action = $_POST['action']; if (isset($action) ) { $name = $_POST['name']; if ($name=="Friday") echo "Have a nice weekend!"; elseif ($name=="Saturday") echo "Tomorrow is Sunday!"; else echo "Please enter Friday or Saturday"; } ?> <form method="post" > Name: <input type="text" size="10" maxlength="40" name="name"> <input type="submit" value="Send"> <input type="hidden" name="action" value="submitted"> </form> Quote Link to comment Share on other sites More sharing options...
w4seem Posted April 11, 2007 Author Share Posted April 11, 2007 works great, thanks! 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.