Page 1 of 1

_POST not catching submit value

Posted: Fri Jun 28, 2002 3:39 pm
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?

Posted: Fri Jun 28, 2002 6:31 pm
by Zmodem
What does your IF statement look like? Can you post some code please? Thanks

Posted: Sat Jun 29, 2002 5:30 am
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...

maybe the answer

Posted: Sat Jun 29, 2002 6:14 pm
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.

Posted: Sun Jun 30, 2002 4:10 am
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;

Posted: Mon Jul 01, 2002 9:03 am
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;

Posted: Mon Jul 01, 2002 3:32 pm
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 ;-)

Posted: Mon Dec 23, 2002 5:25 am
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.