Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Arguments on a button

13 views
Skip to first unread message

bit-n...@hotmail.com

unread,
Jun 2, 2017, 9:25:33 AM6/2/17
to
If I have a button on a page, which when clicked, I want to run "page2.php", with particular arguments, say fruit=papaya&veggies=potato , how do I do that? And how do I read these args INSIDE page2.php?


Thanks.

Lew Pitcher

unread,
Jun 2, 2017, 10:13:04 AM6/2/17
to
bit-n...@hotmail.com wrote:

> If I have a button on a page, which when clicked, I want to run
> "page2.php", with particular arguments, say fruit=papaya&veggies=potato ,
> how do I do that?

You don't need PHP for that; you can satisfy that requirement with pure
HTML:
<form method="post" action="page2.php?fruit=papaya&veggies=potato">
<input type="submit">
</form>

> And how do I read these args INSIDE page2.php?

PHP will set the $_POST[] array with the key/value pairs:
$_POST['fruit'] will be set to "papaya", and
$_POST['veggies'] will be set to "potato"

If the parameter is not supplied, PHP will not set the corresponding
$_POST[] element, which you can test with isset
if (isset($_POST['fruit'])
$fruit_choice=$_POST['fruit'];
else
$fruit_choice="Dont like fruit";

--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request


Lew Pitcher

unread,
Jun 2, 2017, 10:20:16 AM6/2/17
to
Lew Pitcher wrote:

> bit-n...@hotmail.com wrote:
>
>> If I have a button on a page, which when clicked, I want to run
>> "page2.php", with particular arguments, say fruit=papaya&veggies=potato ,
>> how do I do that?
>
> You don't need PHP for that; you can satisfy that requirement with pure
> HTML:
> <form method="post" action="page2.php?fruit=papaya&veggies=potato">
> <input type="submit">
> </form>

Or, more generally (including some HTML formatting)
<form method="post" action="page2.php">
<dl>
<dt>Fruit:</dt>
<dd><input type="text" name="fruit"/></dd>
<dt>Veggie:</dt>
<dd><input type="text" name="veggies"/></dd>
<dt>Submit:</dt>
<dd><input type="submit"/></dd>
</dl>
</form>

Mark Lloyd

unread,
Jun 2, 2017, 12:35:33 PM6/2/17
to
On 06/02/2017 09:12 AM, Lew Pitcher wrote:
> bit-n...@hotmail.com wrote:
>
>> If I have a button on a page, which when clicked, I want to run
>> "page2.php", with particular arguments, say fruit=papaya&veggies=potato ,
>> how do I do that?
>
> You don't need PHP for that; you can satisfy that requirement with pure
> HTML:
> <form method="post" action="page2.php?fruit=papaya&veggies=potato">
> <input type="submit">
> </form>

I used to do that. Now I use a normal link, and use CSS to make it look
like a button.

[snip]

--
Mark Lloyd
http://notstupid.us/

"I can't activate two neurons simultaneously, and I vote" -- The
theistic majority

Lew Pitcher

unread,
Jun 2, 2017, 12:52:02 PM6/2/17
to
Mark Lloyd wrote:

> On 06/02/2017 09:12 AM, Lew Pitcher wrote:
>> bit-n...@hotmail.com wrote:
>>
>>> If I have a button on a page, which when clicked, I want to run
>>> "page2.php", with particular arguments, say fruit=papaya&veggies=potato
>>> , how do I do that?
>>
>> You don't need PHP for that; you can satisfy that requirement with pure
>> HTML:
>> <form method="post" action="page2.php?fruit=papaya&veggies=potato">
>> <input type="submit">
>> </form>
>
> I used to do that. Now I use a normal link, and use CSS to make it look
> like a button.

Good point.

There are many ways to handle this requirement that do not use PHP. Not
knowing the OP's skill level, I refrained from mentioning CSS or
JavaScript; I find no need to confuse him.

Lew Pitcher

unread,
Jun 3, 2017, 10:39:22 AM6/3/17
to
D*mn. It's either senility or complacency that got me here.

I wrote "post", but I meant "get". Mea culpa.

FWIW, I almost never write parameterized "get" pages; I mostly use POST
unless I absolutely have to use GET. P'haps that's what got me off-track.


Lew Pitcher wrote:

> bit-n...@hotmail.com wrote:
>
>> If I have a button on a page, which when clicked, I want to run
>> "page2.php", with particular arguments, say fruit=papaya&veggies=potato ,
>> how do I do that?
>
> You don't need PHP for that; you can satisfy that requirement with pure
> HTML:
> <form method="post" action="page2.php?fruit=papaya&veggies=potato">
> <input type="submit">
> </form>

I meant:

<form method="get" action="page2.php?fruit=papaya&veggies=potato">
<input type="submit">
</form


>> And how do I read these args INSIDE page2.php?
>
> PHP will set the $_POST[] array with the key/value pairs:
> $_POST['fruit'] will be set to "papaya", and
> $_POST['veggies'] will be set to "potato"

I meant:

PHP will set the $_GET[] array with the key/value pairs:
$_GET['fruit'] will be set to "papaya", and
$_GET['veggies'] will be set to "potato"

> If the parameter is not supplied, PHP will not set the corresponding
> $_POST[] element, which you can test with isset
> if (isset($_POST['fruit'])
> $fruit_choice=$_POST['fruit'];
> else
> $fruit_choice="Dont like fruit";
>

I meant:

If the parameter is not supplied, PHP will not set the corresponding
$_GET[] element, which you can test with isset
if (isset($_GET['fruit'])
$fruit_choice=$_GET['fruit'];
else
$fruit_choice="Dont like fruit";

I /really/ should proof-read these posts before I hit send.

Christoph M. Becker

unread,
Jun 5, 2017, 1:41:31 PM6/5/17
to
On 02.06.2017 at 16:12, Lew Pitcher wrote:

> bit-n...@hotmail.com wrote:
>
>> If I have a button on a page, which when clicked, I want to run
>> "page2.php", with particular arguments, say fruit=papaya&veggies=potato ,
>> how do I do that?
>
> You don't need PHP for that; you can satisfy that requirement with pure
> HTML:
> <form method="post" action="page2.php?fruit=papaya&veggies=potato">
> <input type="submit">
> </form>

In this case, I'd use `method="get"`.

--
Christoph M. Becker

Lew Pitcher

unread,
Jun 5, 2017, 2:02:56 PM6/5/17
to
You are correct, of course.

I had a brain fart - I'm too used to writing POST method handlers.

Thomas 'PointedEars' Lahn

unread,
Jun 6, 2017, 2:53:31 PM6/6/17
to
Lew Pitcher wrote:

> Or, more generally (including some HTML formatting)
> <form method="post" action="page2.php">
> <dl>
> <dt>Fruit:</dt>
> <dd><input type="text" name="fruit"/></dd>
> <dt>Veggie:</dt>
> <dd><input type="text" name="veggies"/></dd>
> <dt>Submit:</dt>
> <dd><input type="submit"/></dd>
> </dl>
> </form>

This abuse of *definition lists* (dl) is common in certain CMSs, but not
something that should be repeated.

--
PointedEars
Zend Certified PHP Engineer <http://www.zend.com/en/yellow-pages/ZEND024953>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Christoph M. Becker

unread,
Jun 6, 2017, 5:43:47 PM6/6/17
to
On 06.06.2017 at 20:53, Thomas 'PointedEars' Lahn wrote:

> Lew Pitcher wrote:
>
>> Or, more generally (including some HTML formatting)
>> <form method="post" action="page2.php">
>> <dl>
>> <dt>Fruit:</dt>
>> <dd><input type="text" name="fruit"/></dd>
>> <dt>Veggie:</dt>
>> <dd><input type="text" name="veggies"/></dd>
>> <dt>Submit:</dt>
>> <dd><input type="submit"/></dd>
>> </dl>
>> </form>
>
> This abuse of *definition lists* (dl) is common in certain CMSs, but not
> something that should be repeated.

I wouldn't use a definition list, either. However, the HTML 5.1
specification states[1]:

| Term-description groups may be names and definitions, questions and
| answers, categories and topics, or any other groups of
| term-description pairs.

This suggest a rather loose interpretation, and as such the example
above may not be considered abuse.

[1] <https://www.w3.org/TR/html51/grouping-content.html#the-dl-element>

--
Christoph M. Becker

Thomas 'PointedEars' Lahn

unread,
Jun 7, 2017, 4:35:18 PM6/7/17
to
Christoph M. Becker wrote:

> On 06.06.2017 at 20:53, Thomas 'PointedEars' Lahn wrote:
>> Lew Pitcher wrote:
>>> Or, more generally (including some HTML formatting)
>>> <form method="post" action="page2.php">
>>> <dl>
>>> <dt>Fruit:</dt>
>>> <dd><input type="text" name="fruit"/></dd>
>>> <dt>Veggie:</dt>
>>> <dd><input type="text" name="veggies"/></dd>
>>> <dt>Submit:</dt>
>>> <dd><input type="submit"/></dd>
>>> </dl>
>>> </form>
>>
>> This abuse of *definition lists* (dl) is common in certain CMSs, but not
>> something that should be repeated.
>
> I wouldn't use a definition list, either. However, the HTML 5.1
> specification states[1]:
>
> | Term-description groups may be names and definitions, questions and
> | answers, categories and topics, or any other groups of
> | term-description pairs.
>
> This suggest a rather loose interpretation, and as such the example
> above may not be considered abuse.

You are mistaken. A label and a corresponding form control is _not_ a
“term–description pair” at all. And by “questions and answers”, “label and
corresponding form control” is most definitely _not_ meant; rather, that
which you can find in a FAQ.
0 new messages