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

Aranince

macrumors 65816
Original poster
Apr 18, 2007
1,104
0
California
For some reason...my PHP code does not like checkboxes.

Code:
	// Update the site settings
	public function settingsAction()
	{
		$this->validate();
		if( $this->_request->isPost() )
		{
			if( isset($_POST['enable']) )
			{
				$this->_db->fetchAll( "UPDATE settings SET setting_value='true' WHERE setting_name='site_enabled' LIMIT 1" );
			}
			else
			{
				$this->_db->fetchAll( "UPDATE settings SET setting_value='false' WHERE setting_name='site_enabled' LIMIT 1" );			
			}

		}
		$this->_redirect('/admin');
	}

That code will only set it to false, and not true...no matter the status of the checkbox.

Code:
<sub>Enable Site: <input type="checkbox" name="enable" checked="checked" /></sub>
 
I never liked isset(). Try something like this:
Code:
if ($_POST['enable']=='1') $value = true;

Although, I believe your code isn't working because the checkbox doesn't have a "value" attribute, so it is giving you an empty variable.
 
I never liked isset(). Try something like this:
Code:
if ($_POST['enable']=='1') $value = true;

Although, I believe your code isn't working because the checkbox doesn't have a "value" attribute, so it is giving you an empty variable.

Exactly. Your checkbox needs to have a value or else isset() won't see it as being set.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.