Page 1 of 1

[SOLVED] Checkbox values is not saved when edit

Posted: Mon Aug 27, 2007 12:57 am
by webform
I've installed the Company Directory module in CMSMS 1.1 but has encountered a problem;

I have a list of companies and a list of categories. When i want to edit a company no values in the category checkboxes is checked even though i checked one category or more when i added the company. If i look in the source code  for the edit page i can see a value assigned to the correct checkbox, but there is no checked="checked" so values doesn't get saved on submit unless i check the correct categories one more time!


I've tried to look through action.editcompany.php and found this code snippet there looks like it has to do with setting the values for categories. I've tried to set a variable with checked="checked" in the CreateInputCheckbox. It sets all category checkboxes to checked in admin, so it at least tells me i found the correct code to change - but the question is what to change and how?

Oh and i guess the same problem goes for Field Definitions if whose is added to The Company Directory!

Code: Select all

$categories = $this->GetCategoriesForCompany($compid);
$catarray = array();

if (count($categories) > 0)
{
	foreach ($categories as $fielddef)
	{
		$field = new stdClass();

        $value = '';
        if (isset($fielddef->value))
        {
                $value = $fielddef->value;
        }

		if (isset($_REQUEST[$id.'category']))
		{
			if (isset($_REQUEST[$id.'category']['id-'.$fielddef->id]))
				$value = 'true';
			else
				$value = 'false';
		}
		
		$field->id = $fielddef->id;
		$field->name = $fielddef->name;
		$field->checkbox = $this->CreateInputCheckbox($id, 'category[id-'.$fielddef->id.']', $value, 'true');

		$catarray[] = $field;
	}
}
TIA

Finn

Re: Checkbox values is not saved when edit

Posted: Thu Aug 30, 2007 8:58 pm
by webform
Anyone have a clue how i can solve this problem  ???

The users are not happy the categories disappear every time they update the Company Directory :-\

Re: Checkbox values is not saved when edit

Posted: Sun Sep 02, 2007 10:52 am
by webform
OK! I think i've solved it now  ;D

I inserted this code:

Code: Select all

$extratext = '';
		if( $value != null )
		  {
		$extratext = 'checked="checked"';
		  }
And then this line:

Code: Select all

$field->checkbox = $this->CreateInputCheckbox($id, 'category[id-'.$fielddef->id.']', $value, 'true', $extratext);
So the full code looks like this in action.editcompany.php:

Code: Select all

$categories = $this->GetCategoriesForCompany($compid);
$catarray = array();

if (count($categories) > 0)
{
	foreach ($categories as $fielddef)
	{
		$field = new stdClass();

        $value = '';
        if (isset($fielddef->value))
        {
                $value = $fielddef->value;
        }

		if (isset($_REQUEST[$id.'category']))
		{
			if (isset($_REQUEST[$id.'category']['id-'.$fielddef->id]))
				$value = 'true';
			else
				$value = 'false';
		}
		
		$extratext = '';
		if( $value != null )
		  {
		$extratext = 'checked="checked"';
		  }
		
		$field->id = $fielddef->id;
		$field->name = $fielddef->name;
		$field->checkbox = $this->CreateInputCheckbox($id, 'category[id-'.$fielddef->id.']', $value, 'true', $extratext);

		$catarray[] = $field;
	}
}

Re: [SOLVED] Checkbox values is not saved when edit

Posted: Thu May 22, 2008 8:21 pm
by taylort
I am having this exact same problem and the code above doesn't work. Anyone have any ideas?

Re: [SOLVED] Checkbox values is not saved when edit

Posted: Thu May 22, 2008 8:57 pm
by calguy1000
None of you have followed the forum rules about
a) which forum your submitting to
b) supplying context information
This topic is now closed.