Forum Moderators: coopster
Array ( [field] => This field is ok [option] => Array ( [0] => 1 ) )
Array ( [field] => This field is ok [option] => )
I have also tried with file_get_contents('php://input') to see the raw data and it is also not shown so I think PHP is not receiving the data.
If anyone can help I would be very thankful.
Cheers.
Linux 2.6.9-55.0.2.ELsmp #1 SMP
PHP Version 5.2.3
Apache/2.0.52 (CentOS)
<?php
print_r($_POST);
?>
<form method="POST">
Field: <input name="field" value="This field is ok" /><br/>
Option 1: <input type="radio" name="option[]" value="1" checked=""/><br/>
Option 2: <input type="radio" name="option[]" value="2" /><br/>
<input type="submit" />
</form>
<?php
if (!$_POST['option']) {
echo "There is a problem";
} else {
echo "It is working! :) ";
}
?>
How about
checked="checked"
in that radio group there?
One note of caution, if you are going to use PHP to setup that form action using PHP_SELF you should always strip_tags() [php.net] for security reasons.
<?php
$data = file_get_contents('php://input');
echo "data:". $data. "<br/>\n";
print_r($_POST);
?>
<form method="POST" action="<?php echo $_SERVER['php-self']?>">
Field: <input name="field" value="This field is ok" /><br/>
Option 1: <input type="checkbox" name="option[]" value="1" checked="checked"/><br/>
Option 2: <input type="checkbox" name="option[]" value="2" /><br/>
Option 3: <input type="checkbox" name="option[]" value="3" checked="checked"/><br/>
<select multiple name="snacks[]">
<option value="coke" selected="selected">CocaCola</option>
<option value="popcorn" selected="selected">Popcorn</option>
<option value="peanuts">Peanuts</option>
</select>
<input type="submit" />
</form>
<?php
if ($_POST['field']) {
if (!$_POST['option']) {
echo "There is a problem";
} else {
echo "It is working! :) ";
}
}
phpinfo(INFO_VARIABLES);
?>