Reputation: 236
I am receiving this error when trying to pass a value via hidden input in a form. I have used this multiple times before, and I can't seem to figure out why it is not passing this time in particular.
Code from the form on index:
<form method="post" action="viewchars.php">
<input type="hidden" name="uname" value="testuser" />
</form>
Code on viewchars.php:
<?php
$user = $_POST["uname"];
?>
The error states that uname is the undefined index.
I am not trying to get the error to just go away, as I actually need the value being passed for the viewchars.php page.
Upvotes: 0
Views: 3145
Reputation: 79
just remove "/" form end of input line! like this...
<form method="post" action="viewchars.php">
<input type="hidden" name="uname" value="testuser" >
</form>
Upvotes: 0
Reputation: 1548
add submit button in your html
<form method="post" action="viewchars.php">
<input type="hidden" name="uname" value="testuser" />
<input type="submit" value="Submit"/>
</form>
Upvotes: 1
Reputation: 2960
If you are sending this via JS make sure you are actually using POST. Have you tried to test on $_REQUEST, instead?
Also, try:
use a submit button just to test
make the input visible and type text to test
change var name
try a print_r($_REQUEST); on the php side to see what is received
Upvotes: 0
Reputation: 21
You have to make sure the form is submitted before using POST values. So it should be something like
$user = isset($_POST['uname']) ? $_POST['uname'] : '';
Upvotes: 1