Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17456 > unrolled thread

Arguments on a button

Started bybit-naughty@hotmail.com
First post2017-06-02 06:25 -0700
Last post2017-06-05 14:02 -0400
Articles 11 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  Arguments on a button bit-naughty@hotmail.com - 2017-06-02 06:25 -0700
    Re: Arguments on a button Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-02 10:12 -0400
      Re: Arguments on a button Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-02 10:19 -0400
        Re: Arguments on a button Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-06-06 20:53 +0200
          Re: Arguments on a button "Christoph M. Becker" <cmbecker69@arcor.de> - 2017-06-06 23:44 +0200
            Re: Arguments on a button Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-06-07 22:35 +0200
      Re: Arguments on a button Mark Lloyd <not@mail.invalid> - 2017-06-02 11:35 -0500
        Re: Arguments on a button Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-02 12:51 -0400
      Re: Arguments on a button Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-03 10:39 -0400
      Re: Arguments on a button "Christoph M. Becker" <cmbecker69@arcor.de> - 2017-06-05 19:41 +0200
        Re: Arguments on a button Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-05 14:02 -0400

#17456 — Arguments on a button

Frombit-naughty@hotmail.com
Date2017-06-02 06:25 -0700
SubjectArguments on a button
Message-ID<be64366d-5484-4569-a97c-dab6238b13c0@googlegroups.com>
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.

[toc] | [next] | [standalone]


#17457

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2017-06-02 10:12 -0400
Message-ID<ogrrin$4qu$1@dont-email.me>
In reply to#17456
bit-naughty@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

[toc] | [prev] | [next] | [standalone]


#17458

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2017-06-02 10:19 -0400
Message-ID<ogrs08$6o1$1@dont-email.me>
In reply to#17457
Lew Pitcher wrote:

> bit-naughty@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>

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

[toc] | [prev] | [next] | [standalone]


#17470

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-06-06 20:53 +0200
Message-ID<3988954.LvFx2qVVIh@PointedEars.de>
In reply to#17458
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.

[toc] | [prev] | [next] | [standalone]


#17471

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2017-06-06 23:44 +0200
Message-ID<oh77me$6k3$1@solani.org>
In reply to#17470
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

[toc] | [prev] | [next] | [standalone]


#17472

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-06-07 22:35 +0200
Message-ID<10854412.O9o76ZdvQC@PointedEars.de>
In reply to#17471
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.
 
-- 
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.

[toc] | [prev] | [next] | [standalone]


#17459

FromMark Lloyd <not@mail.invalid>
Date2017-06-02 11:35 -0500
Message-ID<ktgYA.13454$MI5.12743@fx41.iad>
In reply to#17457
On 06/02/2017 09:12 AM, Lew Pitcher wrote:
> bit-naughty@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

[toc] | [prev] | [next] | [standalone]


#17460

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2017-06-02 12:51 -0400
Message-ID<ogs4sr$63n$1@dont-email.me>
In reply to#17459
Mark Lloyd wrote:

> On 06/02/2017 09:12 AM, Lew Pitcher wrote:
>> bit-naughty@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
"In Skills, We Trust"
PGP public key available upon request

[toc] | [prev] | [next] | [standalone]


#17467

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2017-06-03 10:39 -0400
Message-ID<oguhg2$64m$1@dont-email.me>
In reply to#17457
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-naughty@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.
-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

[toc] | [prev] | [next] | [standalone]


#17468

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2017-06-05 19:41 +0200
Message-ID<oh4545$ao3$1@solani.org>
In reply to#17457
On 02.06.2017 at 16:12, Lew Pitcher wrote:

> bit-naughty@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

[toc] | [prev] | [next] | [standalone]


#17469

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2017-06-05 14:02 -0400
Message-ID<oh465n$fd9$1@dont-email.me>
In reply to#17468
Christoph M. Becker wrote:

> On 02.06.2017 at 16:12, Lew Pitcher wrote:
> 
>> bit-naughty@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"`.

You are correct, of course.

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




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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web