_POST not catching submit value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

_POST not catching submit value

Post by RandomEngy »

Hey, been working hard some more on my database and stuff, and recently made an page where one can add and delete users from a database. I really liked jason's way of doing it so I copied him. =D Anyway I have a form on the page:

Code: Select all

<form action="<?=$_SERVER&#1111;'PHP_SELF']?>" method="post">
  <table border="0">
  <tr><td colspan="2" align="center"><b>Delete user</b></td></tr>
  <tr><td>User name:</td><td><input type="text" name="user" size="15"
    maxlength="20"></td></tr>
  <tr><td colspan="2" align="center"><input type="submit" name="submit"
    value="Delete User"></td></tr>
  </table>
  </form>
The form is for deleting users. You type in the user, and click the button, it goes through just fine, and the user is deleted. However when you type it in and hit enter, the page reloads, and $_POST['submit'] is not set when the page reloads, resulting in the user deletion to fail.

Also, on the same page is a Add User form, and it works just fine by using enter. (perhaps because it has a type="password" input?)

I thought I might be making a simple html forms error, by not specifying the default send button or something, but I couldn't find anything insightful about it.

If you need the full context for this, I can post it, but it's a rather large script.

So, anyone know how to fix it?
Zmodem
Forum Commoner
Posts: 84
Joined: Thu Apr 18, 2002 3:59 pm

Post by Zmodem »

What does your IF statement look like? Can you post some code please? Thanks
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

justa guess but not clicking on the button might make the browswer think not to send the value of it... instead of doing things like

Code: Select all

if($submit)&#123;
//statements
&#125;
i try to put something like...

Code: Select all

// form
<form method="post" action="<?=$_SERVER&#1111;'PHP_SELF']?>">
 <input type="text" name="var" />
 <input type="hidden" name="action" value="go" />
 <input type="submit" />
</form>
// end form

//php stuff..
$action = $_POST&#1111;'action'];
if($action == "go")&#123;
/* do stuff with var */
&#125;
//end php stuff
this, however, may be totally irrelevant...
galen
Forum Newbie
Posts: 1
Joined: Sat Jun 29, 2002 6:14 pm

maybe the answer

Post by galen »

$_POST["submit"] is not right. submit is the name of the submit button. in order to get the users name you are trying to delete you need to use the name of the text field the name was typed into. $_POST["user"] will be set to whatever was in the textbox. use that.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

yeah, he has a point..

it would work to just do

Code: Select all

if(isset($_POST&#1111;'user']))&#123;
//delete them
&#125; else &#123;
//display the boxes
&#125;
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Okay, thanks for your help. So I guess there is really no way to fix this annoyance, only get around it? I have another field named "user" and that's for adding users, so I'd have to make the fields named adduser and deluser instead or something, if I want to use hobgoblin's last bit of code. The hidden value seems promising; I'll try to use that. Anyway, my IF statement goes:

Code: Select all

switch( $_POST&#1111;'submit'] ) &#123;
  case 'Add User':
    add_user( $_POST&#1111;'user'], $_POST&#1111;'pass'] );
    break;
  case 'Delete User':
    delete_user( $_POST&#1111;'user'] );
    break;
  default:
    break;
&#125;
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

i always liked using hidden values, yet.. some people might argue that its not worth the effort, i mean wow.. you have to type like 3 extra lines.. heh ;-)
Spinball
Forum Newbie
Posts: 6
Joined: Thu Jun 13, 2002 12:23 pm

Post by Spinball »

I would put a hidden field in there because for examples where you are taking a search field, checking its length won't indicate that they left it empty but hit submit. In this instance you might want to tell them to enter a search keyword, or just present all the data in the database.
Still, not passing the value of the submit button - even though hitting enter is effectively clicking the button - is totally rubbish.
Post Reply