Problem with delivering POST variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Hoheneder

    Problem with delivering POST variable

    Hello,

    I use PHP 4.3.10 and want to deliver a post variable from a PHP page to
    itself.
    In my page mypage.php I have a hidden field named "dbaction" and a form
    button. When clicking the form button a javascript function is called where
    the dbaction hidden field is set to the value "change" (=actn) and then the
    form gets submitted.
    function doAction(actn) {
    document.forms[0].dbaction.value = actn;
    document.forms[0].submit();
    }
    actn is delivered properly here!

    At the recall of mypage.php (after submit) I expect the hidden field
    dbaction as POST variable know. I have the statement
    if (isset($HTTP_PO ST_VARS['dbaction']))
    to ask whether dbaction exists or not. At the first call of mypage.php it
    doesn't exist because there was no post request but after the form submit
    dbaction should exist as post variable (I have defined method=post in my
    <form> tag).
    What now happens is that after the post request dbaction is set but always
    is an empty string instead of having the value "change".
    What's going on here? Why does the post parameter not get delivered as it is
    set before? Why do I get an empty string as delivered value?
    By the way I have the php property "register_globa ls" set off which is
    highly recommended due to security reasons and I want to let it turned off.

    Any help to this would be much appreciated.
    Thanks in advance.

    Nice greetings from
    Thomas


  • Kenneth Downs

    #2
    Re: Problem with delivering POST variable

    Thomas Hoheneder wrote:
    [color=blue]
    > the form gets submitted.
    > function doAction(actn) {
    > document.forms[0].dbaction.value = actn;
    > document.forms[0].submit();
    > }[/color]

    <snip>
    [color=blue]
    > What now happens is that after the post request dbaction is set but always
    > is an empty string instead of having the value "change".[/color]

    <snip>

    got to be something silly. Start with this reality chec. Hardcode the
    doAction(actn) to set

    document.forms[0].dbaction.value = 'realitycheck';

    If it still comes back empty, do a var_dump($_POST ) and see what did come
    back, and find your mistake that way.

    If it does show up as 'realitycheck', you are not passing what you think to
    doAction().

    Hope this helps.

    --
    Kenneth Downs
    Secure Data Software, Inc.
    (Ken)nneth@(Sec )ure(Dat)a(.com )

    Comment

    • Thomas Hoheneder

      #3
      Re: Problem with delivering POST variable

      > document.forms[0].dbaction.value = 'realitycheck';[color=blue]
      >
      > If it still comes back empty, do a var_dump($_POST ) and see what did come
      > back, and find your mistake that way.[/color]

      Now I have set a hard coded value ("realitycheck" ) like above and after that
      the line
      alert(document. forms[0].dbaction.value );
      to get an alert box with the value of dbaction. It always shows -
      correctly - "realityche ck". Furthermore I have given my hidden field a
      default value:
      <input type="hidden" name="dbaction" value="defaultv alue">
      And I have also built in var_dump($_POST ). But after recall of mypage.php
      always the default value "defaultval ue" is shown in the var_dump($_POST ) and
      not the exprected value "realityche ck".
      So it still doesn't work (field gets delivered but with wrong value). Do you
      have any idea how to fix this?
      I can't believe that I cannot deliver field values by php which are set by
      javascript.
      Thanks in advance.

      Nice greetings from
      Thomas


      Comment

      • Kenneth Downs

        #4
        Re: Problem with delivering POST variable

        Thomas Hoheneder wrote:
        [color=blue][color=green]
        >> document.forms[0].dbaction.value = 'realitycheck';
        >>
        >> If it still comes back empty, do a var_dump($_POST ) and see what did come
        >> back, and find your mistake that way.[/color]
        >
        > Now I have set a hard coded value ("realitycheck" ) like above and after
        > that the line
        > alert(document. forms[0].dbaction.value );
        > to get an alert box with the value of dbaction. It always shows -
        > correctly - "realityche ck". Furthermore I have given my hidden field a
        > default value:
        > <input type="hidden" name="dbaction" value="defaultv alue">
        > And I have also built in var_dump($_POST ). But after recall of mypage.php
        > always the default value "defaultval ue" is shown in the var_dump($_POST )
        > and not the exprected value "realityche ck".
        > So it still doesn't work (field gets delivered but with wrong value). Do
        > you have any idea how to fix this?
        > I can't believe that I cannot deliver field values by php which are set by
        > javascript.
        > Thanks in advance.
        >
        > Nice greetings from
        > Thomas[/color]

        Continuing with reality check mode, we should probably strip this down to
        the bare essentials. Create a php file that has only this:

        ----------- FILE:test.php ----------------
        <script>
        function doAction() {
        ob("var1").valu e = "ran_doActi on";
        ob("reality").s ubmit();
        }

        function ob(oname) {
        if (document.getEl ementById)
        return document.getEle mentById(oname) ;
        else if (document.all)
        return document.all[name];
        }
        </script>
        <form name="reality" id="reality" method="post" action="test.ph p">
        <input type="hidden" name="var1" id="var1" value="default" >
        <input type="hidden" name="var2" id="var2" value="leavemea lone">
        <button type="button" onclick="doActi on();">Test me</button>
        </form>
        <?php
        if(isset($_POST["var1"])) { var_dump($_POST ); }
        ?>
        ----------- END FILE:test.php ----------------

        Notice every object has both an id and a name, this is for compatibility,
        and the function "ob" allows you to quickly refer to anything on the page.
        Don't worry about the doctype declaration, <body> or <html> or any of that
        stuff.

        Bring this up and click the button a few times. Once you get this working,
        compare it to your own code and find the differences.

        --
        Kenneth Downs
        Secure Data Software, Inc.
        (Ken)nneth@(Sec )ure(Dat)a(.com )

        Comment

        Working...