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? Quote Link to comment Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 dont use _request use _post $_POST['fieldname'] Quote Link to comment Share on other sites More sharing options...
otuatail Posted August 24, 2007 Author Share Posted August 24, 2007 tried $_POST['submit'] as well Quote Link to comment Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 show your coding. Quote Link to comment 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; ?> Quote Link to comment 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> Quote Link to comment 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 } ?> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 24, 2007 Share Posted August 24, 2007 as jesirose says your missing the name Quote Link to comment 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. Quote Link to comment 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; } } ?> Quote Link to comment 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. Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 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.