0

Very beginner here, please go easy :)

In our database we have a tinyint field secondary_phone_number which is either 0 or 1 value. We use the flourish MVC.

0 = False, 1 = True.

I am trying to display a checkbox that indicates if the secondary_phone_number is true with the following code:

if ($company->setSecondaryPhoneNumber(fRequest::get("secondary_phone_number")) == TRUE) 
{
      $company->setSecondaryPhoneNumber == TRUE;
} else {
      $company->setSecondaryPhoneNumber == FALSE;
}   

Then, displaying it with:

$data['secondaryphonenumber'] = $company->getSecondaryPhoneNumber();

And finally, rendering it in the .tpl with:

<h5>Enable Secondary phone numbers?</h5>
<label>
    <input type="checkbox" name="secondary_phone_number" value="0" {{^secondaryphonenumber}}checked="checked"{{/secondaryphonenumber}}/>
    Yes
</label><br>

Problem is, it's always displaying as Checked....even when the values are 0 in the DB... any help for this newb???!!

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
firecasey
  • 117
  • 9
  • Have you checked the generated html? – zerkms Dec 18 '12 at 00:57
  • Little trick: You don't need to specify `== TRUE` in your if statement, as 1 returns as true. Unless it's a string (mysql returns this by default) in which you'll need to type cast. – Bankzilla Dec 18 '12 at 01:02
  • are you sure you want to be using the comparison `==` operator instead of the assignment `=`? – Ross Dec 18 '12 at 01:33

2 Answers2

2

As Ross points out in his comment, your error is in your assignment (your using conditional == instead of assignment =):

if ($company->setSecondaryPhoneNumber(fRequest::get("secondary_phone_number")) == TRUE) 
{
      $company->setSecondaryPhoneNumber = TRUE;
} else {
      $company->setSecondaryPhoneNumber = FALSE;
}
HorusKol
  • 8,375
  • 10
  • 51
  • 92
0

This is an HTML problem. The checkbox will always show up as checked when you include checked="checked" I just tried it myself. The checkbox should still work fine without that line. I'm not sure what the deal with your framework is so I'm not sure how you will assign values to the this box from your DB dynamically, but it should be possible to assign a value by echoing a statement in to the value attribute of your check input tag.

Check this link out if you want more detail: http://www.w3schools.com/jsref/dom_obj_checkbox.asp

usumoio
  • 3,500
  • 6
  • 31
  • 57
  • But the entire point of the point of the `{{^secondaryphonenumber}}` `{{/secondaryphonenumber}}` is to only display the Checkbox if there is something in the `{{^secondaryphonenumber}}`......right? – firecasey Dec 18 '12 at 03:10
  • ahhh... the first guy looks to be correct. – usumoio Dec 18 '12 at 03:46