By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

Checking if 'button' set with isset() (beginner)

P: n/a
Dear group,
My question may be novice. I have seen codes where the isset() is
used to test weather a user's session ($_SESSION[]) is set before
entering a page. A kind of direct access to a page is not possible.
But I tested with the "input type="button" and the clicking of the
event is not happened. Can any one tell me why. The code:

<html>
<body>

<form name='noname' action='test.php' method=post>
<input type="button" name='button' value='button'>
</form>

</body>
</html>

<?php

if(isset($_REQUEST['button']))
{
echo "clicked";
}

?>

If I change the <input type='submit'then it works, like get
submitted and perform the action. But why not with button?

Mar 23 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sathyashrayan wrote:
Dear group,
My question may be novice. I have seen codes where the isset() is
used to test weather a user's session ($_SESSION[]) is set before
entering a page. A kind of direct access to a page is not possible.
But I tested with the "input type="button" and the clicking of the
event is not happened. Can any one tell me why. The code:

<html>
<body>

<form name='noname' action='test.php' method=post>
<input type="button" name='button' value='button'>
</form>

</body>
</html>

<?php

if(isset($_REQUEST['button']))
{
echo "clicked";
}

?>

If I change the <input type='submit'then it works, like get
submitted and perform the action. But why not with button?
Hi,

<Input type="button"is just a HTML element.
PHP is NOT involved what the receiving browser does with the HTML received.

However, if you press a submit-button, you are posting a form to some
script, in this case PHP.

Keep a sharp eye on what client-server actually is if you want to learn PHP.
WHAT happens at the server?
WHAT happens at the client (browser)?

In short: PHP produces output. That output goes to the browser. Browser
displays it.
If the HTML send to the browser happens to contain a form, then nothing
special happens: it just displays the form.

However, if you submit the form, your browser sends the information
contained in the form to the receiving script.

PHP can see what is posted by examining:
$_POST[] superglobal for forms with method="POST".
and
$_GET[] retrieves all name/value pairs from the URL.

eg, if you make a page with a form that contains:
<input type="text" name="familyname">
and that is posted to PHP (actiontag in the form), then PHP can retrieve
that value via:
$passedFamilyName = $_GET["familyname"];

About the isset(): If you are not sure the form send to PHP contains an
element with the name familyname, you can use isset to test this.
if (isset($_GET["familyname"])){
// code for existence of familyname
} else {
// no familyname
}

Hope that helps.

Regards,
Erwin Moller
Mar 23 '07 #2

P: n/a
On Mar 23, 9:28 pm, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
sathyashrayan wrote:
Dear group,
My question may be novice. I have seen codes where the isset() is
used to test weather a user's session ($_SESSION[]) is set before
entering a page. A kind of direct access to a page is not possible.
But I tested with the "input type="button" and the clicking of the
event is not happened. Can any one tell me why. The code:
<html>
<body>
<form name='noname' action='test.php' method=post>
<input type="button" name='button' value='button'>
</form>
</body>
</html>
<?php
if(isset($_REQUEST['button']))
{
echo "clicked";
}
?>
If I change the <input type='submit'then it works, like get
submitted and perform the action. But why not with button?

Hi,

<Input type="button"is just a HTML element.
PHP is NOT involved what the receiving browser does with the HTML received.
However, if you press a submit-button, you are posting a form to some
script, in this case PHP.

Keep a sharp eye on what client-server actually is if you want to learn PHP.
WHAT happens at the server?
WHAT happens at the client (browser)?

In short: PHP produces output. That output goes to the browser. Browser
displays it.
If the HTML send to the browser happens to contain a form, then nothing
special happens: it just displays the form.

However, if you submit the form, your browser sends the information
contained in the form to the receiving script.

PHP can see what is posted by examining:
$_POST[] superglobal for forms with method="POST".
and
$_GET[] retrieves all name/value pairs from the URL.

eg, if you make a page with a form that contains:
<input type="text" name="familyname">
and that is posted to PHP (actiontag in the form), then PHP can retrieve
that value via:
$passedFamilyName = $_GET["familyname"];

About the isset(): If you are not sure the form send to PHP contains an
element with the name familyname, you can use isset to test this.
if (isset($_GET["familyname"])){
// code for existence of familyname

} else {
// no familyname
}

Hope that helps.
Yes helped a lot. Thanks..

Mar 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.