SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2009
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Missing Something simple in Form POST

    Howdy! I'm missing something very simple in this code and I can't see it. Can someone lend a quick pair of eyes. I know it's something basic but my coffee isn't working this morning. Thanks in advance.
    Code:
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
    <label for="add_header_text_opt">Display Header Option</label>
    <input type="checkbox" name="add_header_text_opt" value="Yes" />
    <p><input type="submit" name="search" value="Create Options" class="button" /></p>
    </form>
    <?php
    if(isset($_POST["submit"])) : ?>
    	<form method="post" action="">
    		<?php if(isset($_POST["add_header_text_opt"]) && $_POST["add_header_text_opt"] = "Yes") : ?>
    			<label for="header_text">Enter text to display in header</label><br />
    			<input type="text" name="header_text" value="Enter Header Text" />
    
    		<?php endif; ?>
    	</form>
    	<?php else : ?>
    	<p>Submit form and your New element should show here</p>
    	<?php endif; ?>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Care to tell us what the problem is?

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2009
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry 'bout that. When I select the check box and submit the form the label and input do not show in the new form.

  4. #4
    SitePoint Zealot
    Join Date
    Sep 2009
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guido2004. With you asking that question I looked at my form again and the submit button had the wrong name in the name element. How frustrating!
    Thanks again

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    $_POST["submit"] doesn't exist. Your button is called 'search' not 'submit'.

    Never mind. Glad you found it yourself

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <html>
      <head>
        <title>Demo</title>
      </head>
      <body>
        <form method="post" action="">
          
          <label for="header_text_option">
            Display Header?
          </label>
          <input type="checkbox" id="header_text_option" name="header_text_option" />
          
          <?php if(array_key_exists('header_text_option'$_POST)): ?>
            <label for="header_text">
              Enter text to display in header
            </label>
            <input type="text" name="header_text" value="Enter Header Text" />
          <?php endif; ?>
          
          <input type="submit" value="Submit" />
          
        </form>
      </body>
    </html>


    Edit:
    Bah, too slow!
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


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
  •