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

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

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

    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.ph p' method=post>
    <input type="button" name='button' value='button'>
    </form>

    </body>
    </html>

    <?php

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

    ?>

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

  • Erwin Moller

    #2
    Re: Checking if 'button' set with isset() (beginner)

    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.ph p' method=post>
    <input type="button" name='button' value='button'>
    </form>
    >
    </body>
    </html>
    >
    <?php
    >
    if(isset($_REQU EST['button']))
    {
    echo "clicked";
    }
    >
    ?>
    >
    If I change the <input type='submit'th en 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="familynam e">
    and that is posted to PHP (actiontag in the form), then PHP can retrieve
    that value via:
    $passedFamilyNa me = $_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

    Comment

    • sathyashrayan

      #3
      Re: Checking if 'button' set with isset() (beginner)

      On Mar 23, 9:28 pm, Erwin Moller
      <since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
      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.ph p' method=post>
      <input type="button" name='button' value='button'>
      </form>
      >
      </body>
      </html>
      >
      <?php
      >
      if(isset($_REQU EST['button']))
      {
      echo "clicked";
      }
      >
      ?>
      >
      If I change the <input type='submit'th en 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="familynam e">
      and that is posted to PHP (actiontag in the form), then PHP can retrieve
      that value via:
      $passedFamilyNa me = $_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..

      Comment

      Working...