BluwAngel Posted March 5, 2012 Share Posted March 5, 2012 i created 2 buttons and how do i pass value of one i click on so i have yes and no button do i need 2 different forms or 1 with different values? any tip, tutorial or code will help Quote Link to comment https://forums.phpfreaks.com/topic/258317-form-with-multiple-buttons/ Share on other sites More sharing options...
AyKay47 Posted March 5, 2012 Share Posted March 5, 2012 If these are two submit buttons, you can check for the value being set to determine which button was clicked and act accordingly. <form> <input type='submit' value='yes' /> <input type='submit' value='no' /> </form> receiving page if(isset($_POST['yes'])) { //do stuff } else if(isset($_POST['no'])) { //do stuff } Quote Link to comment https://forums.phpfreaks.com/topic/258317-form-with-multiple-buttons/#findComment-1324128 Share on other sites More sharing options...
Psycho Posted March 5, 2012 Share Posted March 5, 2012 If these are two submit buttons, you can check for the value being set to determine which button was clicked and act accordingly. <form> <input type='submit' value='yes' /> <input type='submit' value='no' /> </form> receiving page if(isset($_POST['yes'])) { //do stuff } else if(isset($_POST['no'])) { //do stuff } Not quite. A value of a field is not passed as an index in the POST data. In the above, you would also need to set the Names to "yes" and "no" for that PHP logic to work. Or, you need to give your two submit buttons a name and then set the values accordingly. <input type="submit" name="response" value="Yes" /> <input type="submit" name="response" value="No" /> if(isset($_POST['response']) && $_POST['response']=="Yes") { //Yes response } else { //Assume no response } Quote Link to comment https://forums.phpfreaks.com/topic/258317-form-with-multiple-buttons/#findComment-1324161 Share on other sites More sharing options...
AyKay47 Posted March 5, 2012 Share Posted March 5, 2012 Oops, meant name. thanks for noticing that. Quote Link to comment https://forums.phpfreaks.com/topic/258317-form-with-multiple-buttons/#findComment-1324164 Share on other sites More sharing options...
BluwAngel Posted March 5, 2012 Author Share Posted March 5, 2012 this other one works great, thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/258317-form-with-multiple-buttons/#findComment-1324177 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.