Page 1 of 1

Obtaining input ID

Posted: Thu Dec 02, 2010 12:23 pm
by Ricko97
Hello,

I am looking for an appropriate method of obtaining the ID of a newly created form element. For example, in a typical module we might have something like this:

Code: Select all

$smarty->assign('comment_input', $this->CreateTextarea(false, $id, '', 'comment_body', '', $id.'comment_body', '', '', '', ''));
The resulting HTML for the text area is:

Code: Select all

<textarea name="cntnt01comment_body" cols="" rows="" class="cms_textarea" id="cntnt01comment_body"></textarea>
I need a way of obtaining the contents of the "id" attribute from within the same part of the module. I tried this:

Code: Select all

$bbcode_toolbar = $this->BBCode->BBCToolbar($id.'comment_body');
...but it only passes the first character ("c") to the BBCToolbar function.

Am I doing something wrong? Is there a better way of doing it? Or can I simply hardcode it like $this->BBCode->BBCToolbar("cntnt01comment_body"); ?

Any help appreciated. :)

EDIT: ahem. Seems I've managed to figure it out myself afterall. The way I wrote the BBCToolbar function assumed that the only parameter it receives is an array ($params['input']), whereas it was actually receiving one variable containing a string. I changed it to use "$input" instead and it's working fine now. But if there's more of a "proper" way than simply using $id.'whatever', I'd like to know :) thanks.