Form: GET works but POST doesnt!?

Discussion in 'HTML' started by CRON, Oct 20, 2006.

  1. CRON

    CRON Guest

    Hi all:
    I'm a little confused here: When I submit this form with GET it works
    like a dream. But when I use POST, the recieving script just doens't
    recieve the vars. Why would this be?

    the form:
    <form action="0scripts/invite.php" method="POST" enctype="text/plain"
    onSubmit="compileEmails()">
    <textarea name="notes" cols="65" rows="5"
    id="notes"></textarea>
    <p>Your invitation will be sent to the following email
    addresses:
    <input name="loopcount" type="hidden" value="<? echo
    $loopcount;?>">
    <br>
    <textarea name="emaillist" cols="81" rows="5"
    id="emaillist" style="background:#FFFFFF; border-color:#FFFFFF;
    color:#999999; font-weight:normal; font-size:7pt;"></textarea></p>
    <p align="right" class="backLightGrey">
    <input type="submit" name="Submit" value="Send Invites"
    </p>
    </form>


    Thanks a lot
    CiarĂ¡n
     
    CRON, Oct 20, 2006
    #1
    1. Advertising

  2. On 2006-10-20, CRON wrote:
    > Hi all:
    > I'm a little confused here: When I submit this form with GET it works
    > like a dream. But when I use POST, the recieving script just doens't
    > recieve the vars. Why would this be?
    >
    > the form:
    ><form action="0scripts/invite.php" method="POST" enctype="text/plain"
    > onSubmit="compileEmails()">
    > <textarea name="notes" cols="65" rows="5"
    > id="notes"></textarea>
    > <p>Your invitation will be sent to the following email
    > addresses:
    > <input name="loopcount" type="hidden" value="<? echo
    > $loopcount;?>">
    > <br>
    > <textarea name="emaillist" cols="81" rows="5"
    > id="emaillist" style="background:#FFFFFF; border-color:#FFFFFF;
    > color:#999999; font-weight:normal; font-size:7pt;"></textarea></p>
    > <p align="right" class="backLightGrey">
    > <input type="submit" name="Submit" value="Send Invites"
    > </p>
    ></form>


    Does the script that is targeted (0scripts/invite.php) support the
    POST method?

    --
    Chris F.A. Johnson <http://cfaj.freeshell.org>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
     
    Chris F.A. Johnson, Oct 20, 2006
    #2
    1. Advertising

  3. On Thu, 19 Oct 2006 21:56:01 -0400, "Chris F.A. Johnson"
    <> wrote:

    [snip]

    > Does the script that is targeted (0scripts/invite.php) support the
    > POST method?


    To expand on what Chris says, GET variables are in the _GET array
    whereas POST variables are in the _POST array. If you want to get them
    from either array try something like :

    function GetFormValue ($key, $default = '')
    {
    if (array_key_exists ($key, $_POST))
    return $_POST [$key];
    if (array_key_exists ($key, $_GET))
    return $_GET [$key];
    return $default;
    }

    --
    Steven
     
    Steven Saunderson, Oct 20, 2006
    #3
  4. CRON

    Nico Schuyt Guest

    Steven Saunderson wrote:
    > Chris F.A. Johnson


    > [snip]
    >> Does the script that is targeted (0scripts/invite.php) support the
    >> POST method?


    > To expand on what Chris says, GET variables are in the _GET array
    > whereas POST variables are in the _POST array. If you want to get
    > them from either array try something like :
    > function GetFormValue ($key, $default = '')
    > {
    > if (array_key_exists ($key, $_POST))
    > return $_POST [$key];
    > if (array_key_exists ($key, $_GET))
    > return $_GET [$key];
    > return $default;
    > }


    Or: extract($_POST);
    But isn't that a safety risc? I prefer $var=$_POST['var'];

    --
    Nico Schuyt
    http://www.nicoschuyt.nl/
     
    Nico Schuyt, Oct 20, 2006
    #4
  5. CRON

    John Dunlop Guest

    [piggybacking]

    > [CRON:]
    >
    > ><form action="0scripts/invite.php" method="POST" enctype="text/plain"
    > > onSubmit="compileEmails()">


    Only two enctypes must be supported: application/x-www-form-urlencoded
    and multipart/form-data. The behaviour when the enctype is text/plain,
    or any other content-type, is unspecified.

    http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4

    --
    Jock
     
    John Dunlop, Oct 20, 2006
    #5
  6. CRON

    jojo Guest

    Steven Saunderson wrote:

    > [snip]
    >
    >> Does the script that is targeted (0scripts/invite.php) support the
    >> POST method?

    >
    > To expand on what Chris says, GET variables are in the _GET array
    > whereas POST variables are in the _POST array.


    The $_REQUEST-Array contains both, the POST and the GET variables. I'm
    not surte what happens if the same variable is send by post and by get
    but I would guess that the POST-value overrides the other.
     
    jojo, Oct 20, 2006
    #6
  7. CRON

    jojo Guest

    Nico Schuyt wrote:

    [how to read out $_GET and $_POST]

    > Or: extract($_POST);


    This does only make $_POST variables available but not the GET ones. You
    have to add extract($_GET);.

    > But isn't that a safety risc? >


    It is. It has the same effect which was corrected by adding the
    possibility to switch register_globals off: every variable which is
    posted is set, no matter if the author of the script want it to be set
    by the user or not. In some cases one can override the values of
    variables in the script by simply posting variables with the same name
    which is a security problem.

    > I prefer $var=$_POST['var'];


    The better poosibility. Only the variable you want to be set by post (or
    get) are set, all the other post (or get) variables are ignored.
     
    jojo, Oct 20, 2006
    #7
  8. jojo wrote:
    > Steven Saunderson wrote:
    >
    > > [snip]
    >>
    >>> Does the script that is targeted (0scripts/invite.php) support the
    >>> POST method?

    >>
    >> To expand on what Chris says, GET variables are in the _GET array
    >> whereas POST variables are in the _POST array.

    >
    > The $_REQUEST-Array contains both, the POST and the GET variables. I'm
    > not surte what happens if the same variable is send by post and by get
    > but I would guess that the POST-value overrides the other.


    Well does this answer it?

    GET VAR
    Array
    (
    [parameter] => ValueByGet
    )

    POST VAR
    Array
    (
    [parameter] => ValueByPost
    )


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Oct 20, 2006
    #8
  9. Jonathan N. Little wrote:
    > jojo wrote:
    >> Steven Saunderson wrote:
    >>
    >> > [snip]
    >>>
    >>>> Does the script that is targeted (0scripts/invite.php) support the
    >>>> POST method?
    >>>
    >>> To expand on what Chris says, GET variables are in the _GET array
    >>> whereas POST variables are in the _POST array.

    >>
    >> The $_REQUEST-Array contains both, the POST and the GET variables. I'm
    >> not surte what happens if the same variable is send by post and by get
    >> but I would guess that the POST-value overrides the other.

    >
    > Well does this answer it?
    >
    > GET VAR
    > Array
    > (
    > [parameter] => ValueByGet
    > )
    >
    > POST VAR
    > Array
    > (
    > [parameter] => ValueByPost
    > )
    >
    >

    Also not what happens when you access via the $_REQUEST array...

    $_GET VAR
    Array
    (
    [parameter] => ValueByGet
    )

    $_POST VAR
    Array
    (
    [parameter] => ValueByPost
    )

    $_REQUEST VAR
    Array
    (
    [parameter] => ValueByPost


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Oct 20, 2006
    #9
  10. CRON

    jojo Guest

    Jonathan N. Little wrote:

    [snip]
    >>>> To expand on what Chris says, GET variables are in the _GET array
    >>>> whereas POST variables are in the _POST array.
    >>>
    >>> The $_REQUEST-Array contains both, the POST and the GET variables.
    >>> I'm not surte what happens if the same variable is send by post and
    >>> by get but I would guess that the POST-value overrides the other.

    >>
    >> Well does this answer it?
    >>
    >> GET VAR
    >> Array
    >> (
    >> [parameter] => ValueByGet
    >> )
    >>
    >> POST VAR
    >> Array
    >> (
    >> [parameter] => ValueByPost
    >> )
    >>
    >>

    > Also not what happens when you access via the $_REQUEST array...
    >
    > $_GET VAR
    > Array
    > (
    > [parameter] => ValueByGet
    > )
    >
    > $_POST VAR
    > Array
    > (
    > [parameter] => ValueByPost
    > )
    >
    > $_REQUEST VAR
    > Array
    > (
    > [parameter] => ValueByPost
    >
    >

    This is just what I've said: If a variable is posted twice the
    POST-value overrides the GET one. So where is the problem?
     
    jojo, Oct 20, 2006
    #10
  11. jojo wrote:
    > Jonathan N. Little wrote:


    <snip>

    >> Also not what happens when you access via the $_REQUEST array...
    >>
    >> $_GET VAR
    >> Array
    >> (
    >> [parameter] => ValueByGet
    >> )
    >>
    >> $_POST VAR
    >> Array
    >> (
    >> [parameter] => ValueByPost
    >> )
    >>
    >> $_REQUEST VAR
    >> Array
    >> (
    >> [parameter] => ValueByPost
    >>
    >>

    > This is just what I've said: If a variable is posted twice the
    > POST-value overrides the GET one. So where is the problem?


    If the 'parameter' is sent via POST and included via URL simulating a
    GET (how I did the test) that values discrete within respective $_POST
    and $_GET arrays but in $_REQUEST the POST will trump the GET. That was
    all I was illustrating.

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Oct 20, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Warnock
    Replies:
    12
    Views:
    638
    Olrik Larsen
    Sep 10, 2003
  2. F. GEIGER
    Replies:
    3
    Views:
    776
    F. GEIGER
    Aug 6, 2004
  3. SpaceMarine
    Replies:
    3
    Views:
    407
    SpaceMarine
    Jul 3, 2008
  4. Replies:
    3
    Views:
    438
    alex23
    May 27, 2008
  5. J. Muenchbourg
    Replies:
    0
    Views:
    368
    J. Muenchbourg
    Aug 6, 2003
Loading...

Share This Page