SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    adding key to $_POST when submitting form

    I need to add a key (with no value) to $_POST when I submit a form. This key is not from the form. I tried

    $_POST = array("$ankor"=>0);

    thinking that the submit would just add the form data to the end of $_POST, but no joy as in:
    PHP Code:
     echo '<form   action="adj_width.php" method="post">';
    $ankor "a" $counter;
    $counter $counter 1;
    echo 
    '<a name="form_' $ankor '"></a>';
    echo 
    'Width:<input name="' $id '" type="text" />';
    $_POST = array($ankor=>0);
    echo 
    '<input type="submit" value="Submit" />';
    echo 
    '</form>'
    How do I the key (with no value) from $ankor to $_POST?

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,197
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The $_POST super global cannot be used until the form is submitted so setting it won't do anything, the best thing you can do is use a hidden input field with no value and it will work fine.

    PHP Code:
    echo '<form action="adj_width.php" method="post">';
    echo 
    '<input type="hidden" name="' $ankor '" value="" />';
    echo 
    '</form>'

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I understand. Thanks SgtLegend.

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,197
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    No problem, glad to help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •