/    Sign up×
Community /Pin to ProfileBookmark

Can’t get submit button to show in $_POST

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.

[CODE]if (isset($state) && $state == “Submit”) {
print_r($_POST);
extract($_POST);
if (isset($btn_Exam)) {
unset($state);
}
else if (isset($btn_Scoring) || isset($btn_Resubmit)) {
$state = “CheckAnswers”;
}
else if (isset($btn_Solutions)) {
$state = “ShowSolutions”;
}
else if (isset($btn_Summary)) {
$state = “ShowSummary”;
}
}
.
.
.
<body>
.
.
.
<form id=”form-basic-html” name=”form-basic-html” method=”post” action=”<?php echo $PHP_SELF; ?>?state=Submit”>
<?php
if (isset($state) && $state == “CheckAnswers”):
?>
<center>
<input class=”submit-button” type=”submit” id=”btn_Exam” name=”btn_Exam” value=”&lt;&lt;&nbsp;Exam” />
&nbsp;&nbsp;
<input class=”submit-button” type=”submit” id=”btn_Resubmit” name=”btn_Resubmit” value=”Resubmit Answers” />
&nbsp;&nbsp;
<input class=”submit-button” type=”submit” id=”btn_Solutions” name=”btn_Solutions” value=”Solutions&nbsp;&gt;&gt;” />
</center>
<?php
endif;

if (isset($state) && $state == “ShowSolutions”):
?>
<center>
<input class=”submit-button” type=”submit” id=”btn_Scoring” name=”btn_Scoring” value=”&lt;&lt;&nbsp;Scoring” />
&nbsp;&nbsp;
<input class=”submit-button” type=”submit” id=”btn_Summary” name=”btn_Summary” value=”Summary&nbsp;&gt;&gt;” />
</center>
<?php
endif;
?>
.
.
.
</form>
</body>[/CODE]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehDec 13.2005 — Where is [B]$state[/B] coming from?

$_POST['[B]fieldname[/B]']... comes from... <input type="submit" name="[B]fieldname[/B]" value="Send me">

Most people use [B]submit[/B] as the [B]fieldname[/B] for a submit button.
Copy linkTweet thisAlerts:
@chazzyDec 13.2005 — well if you have it setup like this:

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


and your button is this:
<i>
</i>&lt;input type="submit" name="btn_Exam" value="example" /&gt;


then to pull it from post you would do:
[code=php]
$submitbutton = $_POST['btn_Exam'];
[/code]


also, I don't like this:
<i>
</i>value="&amp;lt;&amp;lt;&amp;nbsp;Exam"

it just seems not right.
Copy linkTweet thisAlerts:
@JazzcatCBauthorDec 14.2005 — well if you have it setup like this:

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


and your button is this:
<i>
</i>&lt;input type="submit" name="btn_Exam" value="example" /&gt;


then to pull it from post you would do:
[code=php]
$submitbutton = $_POST['btn_Exam'];
[/code]
[/QUOTE]


Well, I am doing it almost exactly the way you suggest. The only difference is that I use extract($_POST) to extract $_POST into local variables. I also called print_r($_POST), and I could not find btn_Exam in it. So it appears there is still a problem somewhere in this code.
×

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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...