[SOLVED] Checkbox values is not saved when edit

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
User avatar
webform
Power Poster
Power Poster
Posts: 511
Joined: Sat Nov 25, 2006 3:39 pm

[SOLVED] Checkbox values is not saved when edit

Post 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
Last edited by webform on Sun Sep 02, 2007 10:53 am, edited 1 time in total.
User avatar
webform
Power Poster
Power Poster
Posts: 511
Joined: Sat Nov 25, 2006 3:39 pm

Re: Checkbox values is not saved when edit

Post 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 :-\
User avatar
webform
Power Poster
Power Poster
Posts: 511
Joined: Sat Nov 25, 2006 3:39 pm

Re: Checkbox values is not saved when edit

Post 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;
	}
}
taylort

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

Post by taylort »

I am having this exact same problem and the code above doesn't work. Anyone have any ideas?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Locked

Return to “CMSMS Core”