Page 1 of 1

CreateInputDropdown

Posted: Thu Apr 26, 2012 7:56 pm
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"

Re: CreateInputDropdown

Posted: Thu Apr 26, 2012 8:03 pm
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}

Re: CreateInputDropdown

Posted: Thu Apr 26, 2012 8:07 pm
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"];			
				}