Reputation: 95
I'm trying to get a post value from one of my input fields and I want to know if I can use the class field to get the value instead of the post getting it from the value field.
here is my html
<div class="form_group">
<form id="form1" name="paying" method="post" action="payment.php">
<input id="get_200" type="radio" name="payment" value="200" ><label class="get_option_200" for="get_200"><span>$200</span></label><br>
<input id="get_300" type="radio" name="payment" value="300"><label class="get_option_300" for="get_300"><span>$300</span></label><br>
<input class="get_other" id="other" type="text" name="other" value="Enter amount here">
</form>
</div>
My payment.php
$payment = html_entity_decode(str_replace("'", "\'", $_POST["payment"]));
switch ($payment) {
case "200":
echo "200";
break;
case "300":
echo "300";
break;
default:
echo "No payments made";
}
$other = html_entity_decode(str_replace("'", "\'", $_POST["other"]));
if($other == '' || $other == 'Enter amount here'){
echo "Nope";
}else{
echo "Yep";
}
print_r($payment);
die();
As you can see I have 2 radio buttons and thanks to the switch method I can select the correct radio button value which is in the value field. But because the text input value field is the text "Enter amount here" the amount that I've entered doesn't go through to the payment.php and I only get "Enter amount here" instead of the amount I've entered
Upvotes: 0
Views: 66
Reputation: 1663
Change
<input class="get_other" id="other" type="text" name="other" value="Enter amount here">
With:
<input class="get_other" id="other" type="text" name="other" placeholder="Enter amount here">
After click in input, write down your amount.
You can have problems with IE8 and IE9, so you use this tricky tags:
onfocus="this.value = ''" onblur=" if(this.value = '') { value = 'Enter amount here'}"
Upvotes: 3