Suggestion for the API Documentation & CreateInputRadioGroup

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
j88per
Forum Members
Forum Members
Posts: 32
Joined: Mon Mar 23, 2009 4:08 am

Suggestion for the API Documentation & CreateInputRadioGroup

Post by j88per »

Just a suggestion for the API documentation - this confused me for hours and very little in the way of discussion in the forums too.

The API syntax for CreateInputRadioGroup
CmsModule::CreateInputRadioGroup  (  $    id,
$  name,
$  items,
$  selectedvalue = '',
$  addttext = '',
$  delimiter = '',
$  html_id = ''
)

Instead of $ selectedvalue = '',  It might help to say $id=$value.  This way, (if I understand the code correctly), the button's ID has a value and inherits the CHECKED text to the form input in modforms.inc.php. 

I tried and tried and tried to get this to work but in no way would it work without using the $id of the input.  This particular block int he API doc doesn't even mention the selectedvalue field in the text - so you're left to guessing how to use it.
milehigh

Re: Suggestion for the API Documentation & CreateInputRadioGroup

Post by milehigh »

I agree with this to some extent when it comes to the exact syntax needed in optional fields. Sometimes it's a little fuzzy. I spent quite some time on a CreateInputCheckbox item trying to control whether it's set to checked or not checked based on an array stored in a table field as text. In the end when you look at it it's obvious but I try not to create a module unless absolutely necessary so it's not something alot of people use on a regular basis.

For the purposes of people searching the forums I posted what I ended up with. I needed to store the checkbox array results as a comma delim list so I used implode() and explode() to go back and forth. I pulled an example out of the FormBuilder classes but it took a little digging. (I know its different from the OP's question but it's somewhat related!)

In terms of the module API docs...it would be nice to see examples with actual syntax in place. Something people could do with all the extra time we all have on our hands.  ;)

Code: Select all

$sql = "SELECT * FROM " . cms_db_prefix()."module_modulename_tablename";
$db =& $this->GetDb();
$dbresult =& $db->Execute($sql);
$arrayName= array();
while ($dbresult && $row = $dbresult->FetchRow())
	{
	$i = count($arrayName);
	$arrayName[$i]['smartyName'] = $row['fieldName'];
		if(in_array($row['fieldName'],$compareArray))
		{
	    $arrayName[$i]['fieldName'] = $this->CreateInputCheckbox($id,'arrayName[]',$row['fieldName'],'true','checked=checked');
		}
		else
		{
		$arrayName[$i]['fieldName'] = $this->CreateInputCheckbox($id,'arrayName[]',$row['fieldName']);
		}
	}
Post Reply

Return to “Developers Discussion”