0

I want to set the value from a URL parameter to a HTML form input text, like this:

 <div class="input_container">
           <div class="field_container">
           <?php $clave = $_GET['pu'];?>
              <input type="hidden" class="text" name="puntos_libres__id" id="puntos_libres_id" value="<?php echo $clave;?>" >
            </div>
          </div> 

http://.../mispuntoslibres.php?pu=4

The form opens in a modal window, but the value for the input is not passed correctly to the action script. It always pass 0 as value. Any idea why?

1 Answer 1

1

Perhaps performing a pre-check for the $_GET Variable could do. The Snippet below demonstrates what is meant with that:

<?php   $clave = isset($_GET['pu']) ?  $_GET['pu'] : ""; /*TRY DUMPING: $clave*/ ?>
<?php   var_dump($clave); // JUST TO SEE ITS CONTENTS B4 IT GETS TO THE INPUT.   ?>

<div class="input_container">
       <div class="field_container">
            <input type  = "hidden" 
                   class = "text" 
                   name  = "puntos_libres__id" 
                   id    = "puntos_libres_id" 
                   value = "<?php echo $clave;?>" 
             />
      </div>
</div>
Sign up to request clarification or add additional context in comments.

7 Comments

Thank you, but echoing the get variable throws the expected value, 4 in this case.
@mvasco Crazy; huh? And in fact your code is not so much different from this one. Perhaps, you could var_dump() the variable directly to see what you get.....
this is the result: string(1) "4"
@mvasco And how does your URL look like? Could you, please, copy-paste your URL?
@mvasco Perfect... Then the code is ABSOLUTELY RIGHT! Why? Because you just asked for pu which happens to be 4 as the URL says: ?pu=4. But, what where you expecting otherwise?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.