CreateInputDropdown

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
sirber
Forum Members
Forum Members
Posts: 12
Joined: Tue Apr 24, 2012 2:41 pm
Location: Québec, Canada

CreateInputDropdown

Post by sirber »

Hi!

I'm creating a CMSModue->CreateInputDropdown and the html is inverted. Doc sais $items == array('key'=>'value'), but the output is inverted:

Code: Select all

array(2) { [0]=> string(0) "" [3]=> string(6) "test 2" }

Code: Select all

<select class="cms_dropdown" name="mf673fjobs"><option value="" selected="selected">0</option><option value="test 2">3</option></select>
if I invert my values with the key, I could get issues if I have two item with the same name, but different id, I'll lose data.

using CMS Made Simple™ 1.10.3 "Hyacinthe"
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: CreateInputDropdown

Post by calguy1000 »

Yes... this is known. it's a 'flaw' in the module form api.
Good thing we're slowly changing it.

I recommend you do this:
a: push as much of the 'data' to smarty as possible.
b: build the forms as much in smarty as possible.

i.e:

Code: Select all

$smarty->assign('formstart',$this->CreateFormStart($id,'myaction'));
$smarty->assign('formend',$this->CreateFormEnd());
$smarty->assign('actionid',$id);[/color]
$smarty->assign('options',
        array('a'=>'Option A','b'=>'Option B','c'=>'Option C'));
$smarty->assign('myoption','b');
echo $this->ProcessTemplate('myaction.tpl');

and in your template:
[code]{$formstart}
<p><select name="{$actionid}mydropdown">{html_options options=$options selected=$myoption}</select></p>
<p><input type="submit" name="{$actionid}submit" value="Submit"/></p>
{$formend}
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.
sirber
Forum Members
Forum Members
Posts: 12
Joined: Tue Apr 24, 2012 2:41 pm
Location: Québec, Canada

Re: CreateInputDropdown

Post by sirber »

Thank you!
I made a small workaround on it:

Code: Select all

while ($oQs && $aRow = $oQs->FetchRow()) {
					if (isset($aData[$aRow["name"]]))
						$aRow["name"] = $aRow["name"] . "(1)";
					$aData[$aRow["name"]] = $aRow["id"];			
				}
Post Reply

Return to “Developers Discussion”