I am building a site with a number of independant check boxes that collect information about industry topics. I user will check the ones of interest and store “Yes” in the database.

When they return, they will see the ones previously checked and can uncheck if needed.

To this end, I am trying to get a check box to display as checked if the database value is equal to “Yes” and display as unchecked if the value is blank. Also, of the user checks the checkbox on the form, it will send the value of “Yes” back to the database and a value of blank if the check box is unchecked.

So far, I am only able to display the “Yes” or blank for fields. Here is my code so far:

           <input type="text" name="Core_Compentencies__Marketing" value="
<?php echo $port_row->getField('Core_Compentencies::Marketing'); ?>">

Any help is appreciated.


Couple of ways I usually do this. If I have a lot of boxes to do, I use an outside if statement to test the field, such as
[php]<?php if($checkbox == "Yes") { ?>
<input type=“text” name=“Core_Compentencies__Marketing” checked=“checked” value="

<?php echo $port_row->getField('Core_Compentencies::Marketing'); ?>"> <?php } else { ?>

<input type=“text” name=“Core_Compentencies__Marketing” value="

<?php echo $port_row->getField('Core_Compentencies::Marketing'); ?>"> <?php } ?>[/php]

but if I have just a few, I just do the same if statement inside the input.
[php]<input type=“text” name=“Core_Compentencies__Marketing” <? ($checkbox == "yes") ? "checked = 'checked'"? : ' '?>> value="

<?php echo $port_row->getField('Core_Compentencies::Marketing'); ?>">[/php]

Thanks for your help. I tried multiple versions of both of the examples without success. The does not display the check box and when I change the input type to checkbox it does not display when the database field value is yes. I wonder if there is is way to read the “Yes” which I can echo correctly and show a check box that is checked when it is equal to ‘Yes’? My solution can entertain some variety.

Here is my non-working code. Any help is appreciated:

Business_type::Acounting <?php if($port_row == "Yes") { ?> <?php } else { ?> <?php } ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service