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
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trouble passing hidden input value.

    Like the title states I'm having trouble passing a hidden input value in my site. I left a majority of the code out for the sake of brevity

    Header.php
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Site</title>
    
    
    <link rel="stylesheet" href="css/style.css">
    
    </head>
    <body>
    <div class="navbar navbar-fixed-top">
       <div class="navbar-inner">
          <div class="container">
    	  <span class="brand"> <a href="http://localhost/site"><strong>Site</strong></a>
    	  <?php if (isset($_GET['search'])) { $search = $_GET['search']; } ?> - <a href="http://localhost/site/?search=<?php echo $search; ?>">
    	  <?php if (isset($_POST['search_id'])) { $search_id = $_POST['search_id']; echo $search_id; } ?></a></span> 
          </div>
       </div>
    </div>
    Index.php
    Code:
    <!-- INDEX.PHP -->
    <?php include_once('header.php'); ?>
    <?php 
    
    if (isset($_POST['search'])) {
    	$search = $_REQUEST['search'];
    	header("Location: http://localhost/site/?search=$search");
    }
    
    
    if (isset($_GET['search'])) {
    	$search = $_GET['search'];
    	if (isset($_GET['search_id'])) {
    		$search_id = $_GET['search_id'];
    	}
    	include('home.php');
    }
    
    if (!isset($_GET['search'])) {
    ?>
    
    <div class="container" style="margin-top:140px; margin-bottom:280px;">
    	<div class="row">
    		<div class="span8 offset2">
    			<div id="search-area">
    				<form id="my-form" method="post" action="">
    					<input type="text" id="search" name="search" placeholder="Search..." data-provide="typeahead" class="input-large" />
    					<input type="hidden" name="search_id" id="search_id" value="test" />
    				</form>
    			</div>	
    		</div>
    	</div>
    </div>
    
    <?php } ?>
    Home.php just includes header.php with some other static html at the moment but I've tried $_POST, $_REQUEST and $_GET and I just cannot get the "search_id" value (test) in my hidden input to show.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Both 'search' and 'search_id' will be under the $_POST superglobal. You can make it GET if you want by changing the form method.

    But in this case you won't find them anywhere. The form has no method in which it can submit. You need to add a button there so that the form can then be submitted and the $_POST can be retrieved.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply. I was thinking it might have something to do with no submit button but I wasn't sure because after I fill out the search box and hit return the form is submitted and it returns my 'localhost/site/?search=query' but I was able to capture the search_id value by changing the form method to get, Thank you Fou-Lu.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Sounds to me that you have some javascript in use then. The form itself is post, but if you end up with ?search in the GET than I would suspect that JS is in use for that.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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