/    Sign up×
Community /Pin to ProfileBookmark

Can’t get submit button to appear in $_POST

** THIS ISSUE HAS BEEN RESOLVED. THANKS FOR YOUR INTEREST. **

Please pardon me for posting this again, but I have waited two days for someone to respond to my earlier post, and the issue is still not resolved. Thank you for your understanding.

I’m trying to get the form’s submit button name from $_POST so that I can set the state of my page. I found an example on how to do this, but it’s not working for me. Can anyone please take a look at my code below and tell me what is wrong? Thanks much.

Here’s how I declare the start of my form:
PHP Code:

[code]<form id=”form-basic-html” name=”form-basic-html” method=”post” action=”<?php echo $PHP_SELF; ?>?state=Submit”> [/code]

Here’s how I declare my submit button within the form:
Code:

[code]<input type=”submit” name=”btn_Exam” id=”btn_Exam” value=”example” />[/code]

Then, when the form’s action invokes PHP_SELF, I use ‘print_r($_POST) to verify that ‘btn_Exam’ is found, but it’s not.

If ‘btn_Exam’ existed in $_POST, I would extract it thus:

PHP Code:

[code]extract($_POST);
if (isset($btn_Exam)) {
. . .
}[/code]

I can’t figure out why ‘btn_Exam’ does not appear in $_POST. Can anyone please help me with this? Thanks.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@bokehDec 16.2005 — This works for me: [code=php]<form id="form-basic-html" name="form-basic-html" method="post" action="<?php
echo $_SERVER['PHP_SELF'];
?>?state=Submit">
<input type="submit" name="btn_Exam" value="example">
</form>
<?php
extract($_POST);
echo $btn_Exam;
?>[/code]
but personally I wouldn't use such lazy/dodgy code (unless, of course, you don't care if your site gets hacked).
Copy linkTweet thisAlerts:
@JazzcatCBauthorDec 16.2005 — [/code]but personally I wouldn't use such lazy/dodgy code (unless, of course, you don't care if your site gets hacked).[/QUOTE]

Eh? Lazy/dodgy code? I don't understand what you find lazy or dodgy about my code. Would you please clarify? Thanks.
Copy linkTweet thisAlerts:
@JazzcatCBauthorDec 16.2005 — I have found the problem. The issue is fixed so there's no need to reply to this post now. Thanks.
Copy linkTweet thisAlerts:
@bokehDec 16.2005 — Well you are just accepting any key/value pair into your script that anyone chooses to send it. Don't you think that is a major security risk?
Copy linkTweet thisAlerts:
@JazzcatCBauthorDec 19.2005 — Well you are just accepting any key/value pair into your script that anyone chooses to send it. Don't you think that is a major security risk?[/QUOTE]
Well, the key/value pairs have predefined behavior, so anyone entering them manually will only trigger secure behavior that already exists. I'm not sure how someone could hack my site using this, but if you know of a better way to do things, I'd be happy to hear it.
Copy linkTweet thisAlerts:
@ShrineDesignsDec 19.2005 — DO NOT use extract() for $_GET, $_POST, and/or $_COOKIE

use the $_POST array[code=php]<?php
if($_POST)
{
if(array_key_exists('btn_Exam', $_POST))
{
// ...
}
}
?>[/code]
Copy linkTweet thisAlerts:
@NogDogDec 19.2005 — extract() is fine if properly used with namespace security in mind, e.g.:
[code=php]
$_POST['one'] = 1;
$_POST['two'] = 2;
extract($_POST, EXTR_PREFIX_ALL, "POST");
[/code]

You now have variables $POST_one and $POST_two, and as long as you do not name any other variables in your script in the format $POST_xxxx, there is no risk of malicious form postings overwriting non-$_POST variables.
×

Success!

Help @JazzcatCB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...