Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

linux2mac

macrumors 65816
Original poster
Aug 29, 2009
1,330
0
"City of Lakes", MN
Hello,

I have a PHP web form that populates from a MySQL database. I have check boxes on that form that will be marked as checked depending on a "yes" or "no" value from the database. What is strange is that in FireFox, the checkboxes that are flagged to be checked from the database are indeed checked. When viewing the same form in Safari, the checkboxes are blank.

Does anyone know why the checkboxes display as blank in Safari but not Firefox. I am running Firefox 3.6 and Safari 4.0.5. MySQL version is 5.0.26 and PHP is 5.2.5.

Thanks.

Mike
 
I just completed a PHP form and got it to work. But it's hard to tell what's going on without seeing your code.
 
Without a code sample, I'm just making a stab in the dark, but sometimes people just output selected checkboxes like this:
PHP:
<input type="checkbox" name="name" value="true" checked />
And that works... in some browsers. To be completely correct it should really be:
PHP:
<input type="checkbox" name="name" value="true" checked="checked" />

See if that might be the issue.
 
<?php
require_once("globals.php");
include_once("$path/api.inc");


$obj = formFetch("form_candidate_review", $_GET["id"]); #Use the formFetch function from api.inc to get values for existing form.

function chkdata_CB(&$obj, $nam, $var)
{
$objarr = explode(',',$obj{$nam});
foreach ($objarr as $a)
{
if ($a == "$var")
{
$result = "\"checked\"";
}
}
return $result;
}

?>


<td><label><input type="checkbox" name="first_time_check" readonly="ReadOnly" disabled="true" value="yes" <?php $result = chkdata_CB($obj,"first_time_check","yes"); echo $result;?>/></label></td>

This code works in FireFox but not Safari. Fields that have a checked value in the database display check marks in the corresponding check boxes in FireFox when viewing the form but display without check marks in Safari.

I would prefer to use Safari to view my web form and not sure if this is a Safari setting issue, PHP version issue, or code issue. Thanks.

-Mike
 
If it's a browser issue, then what we need to see is the actual HTML output of the script. The PHP code is run server side, so all the browser sees is the resulting HTML.
I'm still curious as to how your code outputs the 'checked' attribute.

Edit:
On second viewing of your post, I believe I'd try changing the line:
PHP:
$result = "\"checked\"";
to
PHP:
$result = "checked=\"checked\"";
 
Here is the HTML output for both browsers that is created by the PHP code.

FIREFOX
<td><label><input type="checkbox" name="first_time_check" readonly="ReadOnly" disabled="true" value="yes" "checked"/></label></td>

SAFARI
<td><label><input type="checkbox" name="first_time_check" readonly="ReadOnly" disabled="true" value="yes" "checked"/></label></td>

I am going to manipulate the PHP code that generates the HTML and see what happens when I use:
Code:
 checked = "checked"
 
Yes, that worked!!

I needed to make the PHP code generate the HTML per your suggestion:
Code:
checked = "checked"


SAFARI HTML
<td><label><input type="checkbox" name="first_time_check" readonly="ReadOnly" disabled="true" value="yes" checked="checked"/></label></td>


Thanks Darth.Titan!!

-Mike
P.S. What Mac editor do you use? I am thinking of getting Coda or Coda2 (if it releases soon).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.