[solved] Multiple search forms on a page -> keep IDs unique?
Posted: Sun Mar 02, 2014 7:43 pm
I want to put two search forms on my pages (one at the top and the other at the bottom), and while the forms’ IDs are unique in that they are numbered sequentially the IDs of the text input field is static, and thus, makes the HTML invalid because the same ID exists twice in the document.
My search template is pretty much original:
The “{$search_actionid}searchinput” is always the same with multiple forms and despite this not being allowed it also causes issues with the label association because the labels focus the wrong input.
I’ve currently employed a workaround in that I’m defining a variable and adding to that var for each subsequent form:
Is there a better way to do this? It doesn’t quite feel right.
My search template is pretty much original:
Code: Select all
{$startform}
<fieldset>
<legend><label for="{$search_actionid}searchinput">{$searchprompt}</label></legend>
<input type="text" id="{$search_actionid}searchinput" name="{$search_actionid}searchinput" size="20" maxlength="50" value="{$searchtext}" {$hogan}/>
{*
<br/>
<input type="checkbox" name="{$search_actionid}use_or" value="1"/>
*}
<input name="submit" value="{$submittext}" type="submit" />
{if isset($hidden)}{$hidden}{/if}
</fieldset>
{$endform}
I’ve currently employed a workaround in that I’m defining a variable and adding to that var for each subsequent form:
Code: Select all
{if isset($seq_num)}{assign var='seq_num' value=$seq_num+1}{else}{assign var='seq_num' value='1'}{/if}
…
…
<input type="text" id="{$search_actionid}searchinput_{$seq_num}" …/>