Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2007
    Location
    near Washington, DC
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem using $_POST and $_GET

    OK, I'm new to php, so this is probably an idiotic oversight, but I swear I've gone over this with a fine tooth comb and can't see what's wrong.

    I have a form that submits data to the server with method="post". However, when I hit submit, the superglobal $_POST appears to be empty. I even tried changing to method="get" / $_GET, and not only did I still have the same problem, but the form data didn't even appear in the url!?!

    Here's the code. The idea is that it reads the form.html file line-by-line. If form data has been submitted, it is supposed to add a value="value" attribute to any input element. It then displays that line.

    register.php
    PHP Code:
    <?php
    $lines 
    file('form.html');

    foreach(
    $lines as $line) {
      if (
    $_POST['action']=='sent') {
        if (
    preg_match('/input id=".+?"/'$line$match)) {
          
    $inputID substr($match[0],10,strlen($match[0])-11);
          
    preg_match('/type=".+?"/'$line$match);
          
    $inputType substr($match[0],6,strlen($match[0])-7);
          
    $insertPoint strpos($line,'type="');
          
    $insertString "value=\"$_POST[$inputID]\" ";
          
    $line substr($line,0,$insertPoint) . $insertString substr($line,$insertPoint-strlen($line));
        }
      }
      echo 
    $line;
    }
    ?>
    form.html
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Essential Inspirations - Register with www.essential-inspirations.com</title>
      <style type="text/css" media="screen, print, projection">
        * {
          margin: 0;
          padding: 0;
        }
        #wrap {
          width: 80%;
          margin: 0 auto;
          border: solid 2px #530;
        }
      </style>
    </head>
    <body>
      <div id="wrap">
        <form id="register" action="register.php" method="post">
          First Name: <input id="fname" type="text" /><br />
          Last Name: <input id="lname" type="text" /><br />
          Username: <input id="username" type="text" /><br />
          Password: <input id="password" type="password" /><br />
          Verify Password: <input id="pwverify" type="password" /><br />
          e-Mail Address: <input id="email" type="text" /><br />
          <input type="hidden" id="action" value="sent" />
          <input type="submit" value="submit" /><br />
        </form>
      </div>
    </body>
    </html>
    Thanks in advance for your help.
    — Wilford Nusser
    Validate Your Code: (X)HTML CSS
    An HTML Email is NOT a Web Page: HTML Email Guide (1.2Mb pdf) Webmail CSS Support
    REGEX: Brought to you by Psychotic Crack-Smoking Monkeys

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,802
    Thanks
    19
    Thanked 157 Times in 148 Posts
    Instead of id, use name:

    Code:
    <form id="register" action="register.php" method="post">
          First Name: <input name="fname" type="text" /><br />
          Last Name: <input name="lname" type="text" /><br />
          Username: <input name="username" type="text" /><br />
          Password: <input name="password" type="password" /><br />
          Verify Password: <input name="pwverify" type="password" /><br />
          e-Mail Address: <input name="email" type="text" /><br />
          <input type="hidden" name="action" value="sent" />
          <input type="submit" value="submit" /><br />
        </form>
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    Regular Coder
    Join Date
    Feb 2007
    Location
    near Washington, DC
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That did it. Thanks for the quick reply.

    I made an incorrect assumption that the name attribute is invalid in XHTML Strict. I guess I needed the reminder to check my assumptions!
    — Wilford Nusser
    Validate Your Code: (X)HTML CSS
    An HTML Email is NOT a Web Page: HTML Email Guide (1.2Mb pdf) Webmail CSS Support
    REGEX: Brought to you by Psychotic Crack-Smoking Monkeys

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by phoenixshade View Post
    That did it. Thanks for the quick reply.

    I made an incorrect assumption that the name attribute is invalid in XHTML Strict. I guess I needed the reminder to check my assumptions!
    Its only invalid on some elements. The form element is one of them but for inputs its acceptable.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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