colap Posted October 6, 2009 Share Posted October 6, 2009 I have four buttons on a php page. If i click a button it will redirect to different php pages. How would i do that with php? Quote Link to comment https://forums.phpfreaks.com/topic/176693-php-navigation/ Share on other sites More sharing options...
Adam Posted October 6, 2009 Share Posted October 6, 2009 PHP isn't event triggered. You'd have to use several forms or JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/176693-php-navigation/#findComment-931537 Share on other sites More sharing options...
Jahren Posted October 6, 2009 Share Posted October 6, 2009 I don't understand. your buttons will resolve a link in plain html anyways. If you want to redirect from php for any reason, try: //Some condition here, like is the guy logged in? header("Location:http//address.com"); link : http://ca3.php.net/manual/en/function.header.php Quote Link to comment https://forums.phpfreaks.com/topic/176693-php-navigation/#findComment-931541 Share on other sites More sharing options...
colap Posted October 6, 2009 Author Share Posted October 6, 2009 I want to navigate/redirect php page with html buttons. Can anyone post sample code? Html button navigation with click event. (Javascript if necessary) Quote Link to comment https://forums.phpfreaks.com/topic/176693-php-navigation/#findComment-931570 Share on other sites More sharing options...
colap Posted October 6, 2009 Author Share Posted October 6, 2009 <form> <input name="ins" type="submit" value="INSERT"> <input name="upt" type="submit" value="UPDATE"> <input name="del" type="submit" value="DELETE"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/176693-php-navigation/#findComment-931576 Share on other sites More sharing options...
Adam Posted October 6, 2009 Share Posted October 6, 2009 You need to link the form to your PHP file, and then check to see which submit button was pressed using a pretty simple series of IF statements... for example: HTML: <form action="yourpage.php" action="post"> <input name="ins" type="submit" value="INSERT"> <input name="upt" type="submit" value="UPDATE"> <input name="del" type="submit" value="DELETE"> </form> "yourpage.php": if (isset($_POST['ins'])) { echo 'INSERT...'; } elseif (isset($_POST['upt'])) { echo 'UPDATE...'; } elseif (isset($_POST['del'])) { echo 'DELETE...'; } Quote Link to comment https://forums.phpfreaks.com/topic/176693-php-navigation/#findComment-931584 Share on other sites More sharing options...
colap Posted October 6, 2009 Author Share Posted October 6, 2009 You need to link the form to your PHP file, and then check to see which submit button was pressed using a pretty simple series of IF statements... for example: HTML: <form action="yourpage.php" action="post"> <input name="ins" type="submit" value="INSERT"> <input name="upt" type="submit" value="UPDATE"> <input name="del" type="submit" value="DELETE"> </form> "yourpage.php": if (isset($_POST['ins'])) { echo 'INSERT...'; } elseif (isset($_POST['upt'])) { echo 'UPDATE...'; } elseif (isset($_POST['del'])) { echo 'DELETE...'; } No. If i click insert button,it will redirect to insert.php file,similarly update button-->update.php delete button -->delete.php I don't want to display the yourpage.php file for the click event of these three buttons. I'm trying "different page display for different button's click event". Quote Link to comment https://forums.phpfreaks.com/topic/176693-php-navigation/#findComment-931594 Share on other sites More sharing options...
Adam Posted October 6, 2009 Share Posted October 6, 2009 Well then you'll need 3 different forms, or to use JavaScript. JS however, as mentioned before, is un-reliable. Going with a similar idea to mine though; you could link to the other page, decide on the action you need to take, and then redirect as appropriate. Look into header for that. Quote Link to comment https://forums.phpfreaks.com/topic/176693-php-navigation/#findComment-931606 Share on other sites More sharing options...
colap Posted October 6, 2009 Author Share Posted October 6, 2009 Well then you'll need 3 different forms, or to use JavaScript. JS however, as mentioned before, is un-reliable. Going with a similar idea to mine though; you could link to the other page, decide on the action you need to take, and then redirect as appropriate. Look into header for that. Why isn't javascript reliable? I have also tried this.But it's not working. <form > <input name="ins" type="submit" value="INSERT" onclick="location.href='byte.html'"> <input name="upt" type="submit" value="UPDATE"> <input name="del" type="submit" value="DELETE"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/176693-php-navigation/#findComment-931620 Share on other sites More sharing options...
colap Posted October 6, 2009 Author Share Posted October 6, 2009 It works.But how would i use header() here instead of action=""? <form action="byte.html"> <input name="ins" type="submit" value="INSERT"> </form> <form action="stp.php"> <input name="upt" type="submit" value="UPDATE"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/176693-php-navigation/#findComment-931628 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.