I have an html textbox that was written like this:
echo "<b>Quantity:</b> <input type=\"text\" name=\"qtyBox\" value=\"1\" size=\"1\" />";
When the form is submitted I collect the value of the textbox like this:
$_SESSION['qtyBox'] = $_POST['qtyBox'];
$qtyBox = $_SESSION['qtyBox'];
echo $qtyBox;
The problem is that no matter what I type into the text box, the value is echoed out as 1. If I leave the value blank and type a number into the box, I get a blank too.
Can't Override the Default Value of the Textbox
Started by makamo66, May 18 2010 01:35 PM
4 replies to this topic
#1
Posted 18 May 2010 - 01:35 PM
|
|
|
#2
Posted 18 May 2010 - 03:20 PM
Makamo66
What you have done is perfectly correct, there is no issue with it. You have the "value" set to "1", so it will give you "1". If you don't set the "value", then it will give you nothing back.
Try this.
if !(isset($_POST['qtyBox'])
{
$qtyBox = 1;
}
else
{
$qtyBox = $_POST['qtyBox'];
}
echo "<form action='".$SERVER['PHP_SELF']."' method='POST'>";
echo "<b>Quantity:</b> <input type='text' name='qtyBox' value='$qtyBox' size='1' />";
echo "<input type='submit' value='Send Qty' />";
echo "</form>";
(The above code does work. I use it all the time.)
What you have done is perfectly correct, there is no issue with it. You have the "value" set to "1", so it will give you "1". If you don't set the "value", then it will give you nothing back.
Try this.
if !(isset($_POST['qtyBox'])
{
$qtyBox = 1;
}
else
{
$qtyBox = $_POST['qtyBox'];
}
echo "<form action='".$SERVER['PHP_SELF']."' method='POST'>";
echo "<b>Quantity:</b> <input type='text' name='qtyBox' value='$qtyBox' size='1' />";
echo "<input type='submit' value='Send Qty' />";
echo "</form>";
(The above code does work. I use it all the time.)
Edited by Drew, 19 May 2010 - 03:14 PM.
#3
Posted 19 May 2010 - 01:11 AM
can you post the whole form code? And are you sure that the form is submitted via post?
#4
Posted 19 May 2010 - 03:32 AM
The code posted by AndyW should work.
#5
Posted 19 May 2010 - 03:13 PM
If you don't want POST, then the forms information will appear in the location bar upon posting. This can allow eople to do whatever they want to a form at times. So use GET with care.
if !(isset($_GET['qtyBox'])
{
$qtyBox = 1;
}
else
{
$qtyBox = $_GET['qtyBox'];
}
echo "<form action='".$SERVER['PHP_SELF']."' method='GET'>"; //Set to GET so can see what is actually being passed.
echo "<b>Quantity:</b> <input type='text' name='qtyBox' value='$qtyBox' size='1' />";
echo "<input type='submit' value='Send Qty' />";
echo "</form>";
if !(isset($_GET['qtyBox'])
{
$qtyBox = 1;
}
else
{
$qtyBox = $_GET['qtyBox'];
}
echo "<form action='".$SERVER['PHP_SELF']."' method='GET'>"; //Set to GET so can see what is actually being passed.
echo "<b>Quantity:</b> <input type='text' name='qtyBox' value='$qtyBox' size='1' />";
echo "<input type='submit' value='Send Qty' />";
echo "</form>";


Sign In
Create Account


Back to top









