LISE Custom Search Template Topic is solved

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
webform
Power Poster
Power Poster
Posts: 460
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

LISE Custom Search Template

Post by webform »

I am confused about how to create a custom search template.

I have a number of select fields, but after each select the actionid for the subsequent fields changes and the search fails.

Here is an example of a custom search template:

Code: Select all

<div id="{$modulealias}_search" class="card bg-contrast-0 rounded-6 border-0 shadow">
	<div class="card-body p-5">
	{$formstart|replace:'method="post"':'method="get"'}
		<div class="row">

			<div class="col-12 form-group">
				<label for="{$modulealias}searchinput">Search Terms: {$actionid}</label>
				<input class="form-control" type="text" id="{$modulealias}searchinput" name="{$actionid}search" size="20" maxlength="50" value="" />
			</div>
		
		{foreach from=$fielddefs item=fielddef}

		{if $fielddef->alias == 'category'}
			<div class="col-12 form-group">
				<label for="{$modulealias}category">Category: {$actionid}</label>
				<select class="form-select" id="{$modulealias}category" name="{$actionid}search_{$fielddef->alias}">
					<option value="" selected="selected">- None -</option>
					{LISElldb action='category' template_category='categorySearch'}
				</select>
			</div>
		{/if}

		{if $fielddef->alias == 'project'}
			<div class="col-12 form-group">
				<label for="{$modulealias}project">Project: {$actionid}</label>
				<select class="form-select" id="{$modulealias}project_lise_instance" name="{$actionid}search_{$fielddef->alias}">
					<option value="" selected="selected">- None -</option>
					{LISEProjects template_summary='projectSearch' orderby='custom_project_code|DESC'}
				</select>
			</div>
		{/if}

		{/foreach}

			<div class="submit">
				<input class="button button-large button-dark rounded m-0" name="submit" value="{$mod->ModLang('search')}" type="submit" />
			</div>

		</div>
	{$formend}
	</div>
</div>
I get the same result with or without the foreach in the template.

I have also tried to use the default filter template, but there are all select fields without values.

Code: Select all

{LISElldb action='search' filter='status' summarypage='search-result' template_search='filter'}
Output var dump:

Code: Select all

lisefd_Dropdown Object
(
    [id:protected] => 2
    [name:protected] => Status
    [alias:protected] => status
    [description:protected] => 
    [type:protected] => Dropdown
    [friendlytype:protected] => Dropdown
    [value:protected] => LISEFielddefValue Object
        (
            [storage:ArrayObject:private] => Array
                (
                )

        )

    [originator:protected] => LISE
    [active:protected] => 1
    [disabled:protected] => 
    [path:protected] => /var/www/domain.dk/public_html/app/lldb/modules/LISE/lib/fielddefs/Dropdown
    [position:protected] => 4
    [required:protected] => 0
    [options:protected] => Array
        (
            [0] => Draft
Ready For Review
Validated
            [options] => Draft
Ready For Review
Validated
        )

    [caller:protected] => LISElldb
    [item_id:protected] => -1
    [parent_array:protected] => LISEFielddefArray Object
        (
            [_parent_item:LISEFielddefArray:private] => 
            [storage:ArrayObject:private] => Array
                (
                    [2] => lisefd_Dropdown Object
 *RECURSION*
                )

        )

    [template:protected] => {$fielddef.name}: {$fielddef.value}
    [view:protected] => 
    [hastemplate:protected] => 1
    [event_handler:protected] => 
    [values] => Array
        (
        )

)
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE Custom Search Template

Post by velden »

I would try to save the actionid to a custom variable at the very start of your template.
I expect the actionid to be overwritten when you call LISE from inside your template.
webform
Power Poster
Power Poster
Posts: 460
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: LISE Custom Search Template

Post by webform »

Thank a lot Velden, that did the trick and my actionid is now consistent through all fields.

My final custom search template:

Code: Select all

{$form_actionid = $actionid}
<div id="{$modulealias}_search" class="card bg-contrast-0 rounded-6 border-0 shadow">
	<div class="card-body p-5">
	{$formstart|replace:'method="post"':'method="get"'}
		<div class="row">

			<div class="col-12 form-group">
				<label for="{$modulealias}searchinput">Search Terms:</label>
				<input class="form-control" type="text" id="{$modulealias}searchinput" name="{$form_actionid}search" size="20" maxlength="50" value="" />
			</div>

			<div class="col-12 form-group">
				<label for="{$modulealias}category">Category:</label>
				<select class="form-select" id="{$modulealias}category" name="{$form_actionid}category">
					<option value="" selected="selected">- None -</option>
					{LISElldb action='category' template_category='categorySearch'}
				</select>
			</div>

			<div class="col-12 form-group">
				<label for="{$modulealias}project_lise_instance">Project:</label>
				<select class="form-select" id="{$modulealias}project" name="{$form_actionid}search_project">
					<option value="" selected="selected">- None -</option>
					{LISEProjects template_summary='projectSearch' orderby='custom_project_code|DESC'}
				</select>
			</div>

			<div class="submit">
				<input class="button button-large button-dark rounded m-0" name="submit" value="{$mod->ModLang('search')}" type="submit" />
			</div>

		</div>
	{$formend}
	</div>
</div>
Note: Field names are usually written name="{$form_actionid}search_myfieldalias", but since I also have a category field that I couldn't get to work, I discovered that the field name should be written differently and be name="{$form_actionid}mycategoryfieldalias".
And now i can search/filter based on values in all or just some of the search fields.

I hope others can use it for something.
Post Reply

Return to “Modules/Add-Ons”