otuatail Posted August 24, 2007 Share Posted August 24, 2007 I have a form with several buttons all named submit with difrent values. form action ="post" I should be able to get the selected button by $a = $_REQUEST['submit']; but nothing. why? Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/ Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 dont use _request use _post $_POST['fieldname'] Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-332973 Share on other sites More sharing options...
otuatail Posted August 24, 2007 Author Share Posted August 24, 2007 tried $_POST['submit'] as well Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-332978 Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 show your coding. Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-332979 Share on other sites More sharing options...
otuatail Posted August 24, 2007 Author Share Posted August 24, 2007 <? ?> <html> <body> <form action="action.php" method="post"> <table> <tr> <td><input type="submit" value="Add Entry"></td> <td><input type="submit" value="Edit/Delete Entry"></td> </tr> </table> </form> </body> </html> ------------- <? $a = $_POST['submit']; echo $a; ?> Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-332982 Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 try this <td><input type="submit[]" value="Add Entry"></td> <td><input type="submit[]" value="Edit/Delete Entry"></td> Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-332984 Share on other sites More sharing options...
Jessica Posted August 24, 2007 Share Posted August 24, 2007 Or give them different names. <td><input type="submit" name="Add" value="Add Entry"></td> <td><input type="submit" name="Edit" value="Edit/Delete Entry"></td> Then <? if(isset($_POST['Edit'])){ //edit here }else if(isset($_POST['Add'])){ //Add here } ?> Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-332986 Share on other sites More sharing options...
MadTechie Posted August 24, 2007 Share Posted August 24, 2007 as jesirose says your missing the name Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-332988 Share on other sites More sharing options...
otuatail Posted August 24, 2007 Author Share Posted August 24, 2007 The idea of having the same name is that I can do a select case statment. Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-332994 Share on other sites More sharing options...
MadTechie Posted August 24, 2007 Share Posted August 24, 2007 thats fine.. but you don't even have any name set! EDIT: try this <td><input type="submit" name="submit" value="Add Entry"></td> <td><input type="submit" name="submit" value="Edit/Delete Entry"></td> <? if(isset($_POST['submit'])) { switch($_POST['submit']) { case "Add Entry": echo "Add"; break; case "Edit/Delete Entry": echo "delete"; break; } } ?> Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-332996 Share on other sites More sharing options...
Jessica Posted August 24, 2007 Share Posted August 24, 2007 What is a select case? Do you mean a switch? If you're only going to have those two options of Edit and Add that's a bit overkill. Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-332997 Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 well my method is what you shoudl use lol. <td><input type="submit" name="submit[]" value="Add Entry"></td> <td><input type="submit" name="submit[]" value="Edit/Delete Entry"></td> then its an array... [code=php:0]<?php switch($_POST[submit]){ case 0: return a; break; case 1: default: return b; break; } [/code] Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-333000 Share on other sites More sharing options...
MadTechie Posted August 24, 2007 Share Posted August 24, 2007 What is a select case? Do you mean a switch? Yep, Select case is VB for switch Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-333003 Share on other sites More sharing options...
otuatail Posted August 24, 2007 Author Share Posted August 24, 2007 Sorry guys. been a long day it works if it has a name. Thanks. I was going to have a lot more than 2 options. plus if i have 10 difrent web pages all linking to one action.php it makes it easy to use the switch statment. Thanks. Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-333005 Share on other sites More sharing options...
Jessica Posted August 24, 2007 Share Posted August 24, 2007 Good! Don't forget to mark it Solved Link to comment https://forums.phpfreaks.com/topic/66500-solved-get-value-of-submit-button/#findComment-333008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.