Forums / Developer / Dynamic fetch using simple form

Dynamic fetch using simple form

Author Message

steve walker

Monday 23 August 2004 9:53:12 am

Hi there,

I am creating a fetch that runs off a form in order to use the fetch as a type of search facility (see http://ez.no/community/forum/setup_design/advanced_search_development_homemade_fuzzy_logic )

I have created a simple form:

{let exactresults=fetch(content,tree,hash(parent_node_id, 59, 
                                          attribute_filter, array(and,
                                                            array('stone_product/carat','in','($search_carat)'),
                                                            array('stone_product/clarity','in','($search_clarity)'))))
 }

<form action={"/gia_certificated_diamonds"|ezurl} method="get">
<div class="maincontentheader">
<h1>Stone Search</h1>
</div>

<div class="block">
<label>{"Carat"|i18n("design/standard/content/search")}</label><div class="labelbreak"></div>
<input class="box" type="text" size="40" name="search_carat" value="{$search_carat|wash}" />
</div>

<div class="block">
<label>{"Clarity"|i18n("design/standard/content/search")}</label><div class="labelbreak"></div>
<input class="box" type="text" size="40" name="search_clarity" value="{$search_clarity|wash}" />
</div>

<div class="break"></div>
</div>

<div class="buttonblock'">
<input class="button" type="submit" name="SearchButton" value="{'Search'|i18n('design/standard/content/search')}" />
</div>

<h2>Display the Results</h2>
{section var=exactresults loop=$exactresults sequence=array(bglight,bgdark)}

   {node_view_gui view=line content_node=$exactresults.item}<br>
  
{/section}

</form>
{/let}

But when the page submits to itself the variables are in the url (get results: http://127.0.0.1/local/gia/index.php/gia/gia_certificated_diamonds?search_carat=7&search_clarity=7&SearchButton=Search) but no results appear in the display section.

Can anyone see whats going wrong with the web form?

Thanks, Steve.

http://www.oneworldmarket.co.uk

steve walker

Monday 23 August 2004 9:57:07 am

Sorry - have realised nothing is pulling the 'get' variables in at the top of the page - please ignore...

Steve

http://www.oneworldmarket.co.uk

steve walker

Monday 23 August 2004 10:30:02 am

Hi,

Have got a form looking like this:

<?php
$search_carat = isset($_GET['search_carat']) ? $_GET['search_carat'] : "7";
$search_clarity = isset($_GET['search_clarity']) ? $_GET['search_clarity'] : "7";
?>

{let exactresults=fetch(content,tree,hash(parent_node_id, 59, 
                                          attribute_filter, array(and,
                                                                  array('stone_product/carat','in','($search_carat)'), 
                                                                  array('stone_product/clarity','in','($search_clarity)'))))
}

<form action={"/gia_certificated_diamonds"|ezurl} method="get">
<div class="maincontentheader">
<h1>Stone Search</h1>
</div>

<div class="block">
<label>{"Carat"|i18n("design/standard/content/search")}</label><div class="labelbreak"></div>
<input class="box" type="text" size="40" name="search_carat" value="{$search_carat|wash}" />
</div>

<div class="block">
<label>{"Clarity"|i18n("design/standard/content/search")}</label><div class="labelbreak"></div>
<input class="box" type="text" size="40" name="search_clarity" value="{$search_clarity|wash}" />
</div>

<div class="break"></div>
</div>

<div class="buttonblock'">
<input class="button" type="submit" name="SearchButton" value="{'Search'|i18n('design/standard/content/search')}" />
</div>

<h2>Display the Results</h2>
values of carat: <?php echo $_GET["search_carat"]; ?>
values of clarity: <?php echo $_GET["search_clarity"]; ?>
{section var=exactresults loop=$exactresults sequence=array(bglight,bgdark)}

   {node_view_gui view=line content_node=$exactresults.item}<br>
  
{/section}

</form>
{/let}

and have put some very simple '<?php echo $_GET["search_clarity"]; ?>' statements into the page to check that the get is working, but no values show up though the data is in the url.

Are there any special considerations to take into account when creating forms in Ez?

Regards, Steve

http://www.oneworldmarket.co.uk

Paul Forsyth

Monday 23 August 2004 12:15:08 pm

I dont believe the PHP statements are executed by eZ. If you are trying to get http vars try something like ezhttp:

http://ez.no/ez_publish/documentation/reference/template_operators/data_extraction/ezhttp

paul

--
http://www.visionwt.com

steve walker

Tuesday 24 August 2004 12:10:58 am

Fantastic, thanks Paul.

Steve.

http://www.oneworldmarket.co.uk

steve walker

Monday 30 August 2004 8:38:03 am

Hi there,

I am struggling with the syntax adding a variable into a fetch.

I have a fetch that works fine:

{let exactresults=fetch(content,tree,hash(parent_node_id, 59, 
attribute_filter,  
array(and,array('stone_product/carat','in','(7)'), 
array('stone_product/clarity','in','(7)')))) }

This is using Paul's contributed patch found at http://ez.no/community/contributions/hacks/more_attribute_filter_operators_and_fetch_by_owner_id

This fetch lives in the form posted earlier in the thread. I'm trying to add the value of a GET variable into this fetch so that the fetch takes the value from the form, and have almost working code:

{let carat=ezhttp( 'search_carat', 'get' )}
{let exactresults=fetch(content,tree,hash(parent_node_id, 59, 
attribute_filter,  
array(and,array('stone_product/carat','in','($carat)'), 
array('stone_product/clarity','in','(7)'))))
 }
PRINT THE VARIABLE {$carat}

What I'm seeing is that the variable $carat exists and has been GET'd properly (as its displayed via "PRINT THE VARIABLE {$carat}"), but the fetch doesnt use the variable in this manner.

Debug says:
<i>
Query error: Unknown column '$carat' in 'where clause'. Query: SELECT ezcontentobject.*,
</i>

So it seems that the fetch believes $carat is a dbase column.

Can anyone tell me how to change the syntax of

{let exactresults=fetch(content,tree,hash(parent_node_id, 59, 
attribute_filter,  
array(and,array('stone_product/carat','in','($carat)'), 
array('stone_product/clarity','in','(7)'))))
 }

so that the value is $carat is populated correctly?

Thanks, Steve.

http://www.oneworldmarket.co.uk

Paul Borgermans

Monday 30 August 2004 9:59:43 am

Steve,

I think you stumbled upon a bug,

try this workaround

{let carat_in='('|concat($carat,')')
exactresults=fetch(content,tree,hash(parent_node_id, 59, 
attribute_filter,  
array(and,array('stone_product/carat','in',$carat_in), 
array('stone_product/clarity','in','(7)'))))
 }

I use a similar construct on an array of checkbox form elements and have to assemble the string for 'in' filtering outside the fetch, so i did not notice this bug/feature yet.

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

steve walker

Monday 30 August 2004 10:19:58 am

Paul,

Thanks - that's done the trick. I also added the second clarity variable into the mix so I have:

{let carat=ezhttp( 'search_carat', 'get' )}
{let clarity=ezhttp( 'search_clarity', 'get' )}

{let carat_in='('|concat($carat,')') 
let clarity_in='('|concat($clarity,')')
let exactresults=fetch(content,tree,hash(parent_node_id, 59, 
attribute_filter,  
array(and,array('stone_product/carat','in',$carat_in), 
array('stone_product/clarity','in',$clarity_in))))
 }
carat is {$carat_in} and clarity is {$clarity_in}

and the searching is working well :)

Now to add the other 2 variables and get that fuzzy logic stuff working :(

Cheers for the help!

Steve.

http://www.oneworldmarket.co.uk

Paul Borgermans

Monday 30 August 2004 11:40:43 am

Steve,

What is missing to get the fuzzy search working?

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

steve walker

Monday 30 August 2004 12:06:09 pm

Paul,

Not too much - have got plenty to work on thanks to http://ez.no/community/forum/setup_design/advanced_search_development_homemade_fuzzy_logic - just a time issue at present!

I will post end result work in case it could be useful to others.

Cheers, Steve.

http://www.oneworldmarket.co.uk

steve walker

Tuesday 07 September 2004 1:05:48 am

Paul,

I seemed to have stumbled into an issue with the fetches. The fetch works fine if I search on a number, but if I put any text into the search fields I get sql errors.

Say I put in the letter 'F' I see:

Query error: Unknown column 'F' in 'where clause'. Query: SELECT ezcontentobject.*,
                           ezcontentobject_tree.*,
                           ezcontentclass.name as class_name
                           
                           , ezcontentobject_name.name as name,  ezcontentobject_name.real_translation 
                    FROM
                          ezcontentobject_tree,
                          ezcontentobject,ezcontentclass
                          , ezcontentobject_name 
                          
                          , ezcontentobject_attribute a0 , ezcontentobject_attribute a1 , ezcontentobject_attribute a2 
                          
                       WHERE
                           path_string like '/1/2/59/%' and 
                          
                          
                          
                               a0.contentobject_id = ezcontentobject.id AND
                               a0.contentclassattribute_id = 203 AND
                               a0.version = ezcontentobject_name.content_version AND
                               a0.language_code = ezcontentobject_name.real_translation AND 
                               a1.contentobject_id = ezcontentobject.id AND
                               a1.contentclassattribute_id = 210 AND
                               a1.version = ezcontentobject_name.content_version AND
                               a1.language_code = ezcontentobject_name.real_translation AND 
                               a2.contentobject_id = ezcontentobject.id AND
                               a2.contentclassattribute_id = 204 AND
                               a2.version = ezcontentobject_name.content_version AND
                               a2.language_code = ezcontentobject_name.real_translation AND 
                            ( a0.sort_key_string IN (1)  AND a1.sort_key_string IN (F)  AND a2.sort_key_string IN (dv)  ) AND 
                          ezcontentclass.version=0 AND
                          node_id != 59 AND
                          ezcontentobject_tree.contentobject_id = ezcontentobject.id  AND
                          ezcontentclass.id = ezcontentobject.contentclass_id AND
                          
                          
                          ezcontentobject_tree.contentobject_is_published = 1
                           and  ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id and
                              ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version and
                              ezcontentobject_name.content_translation = 'eng-GB' 
                           AND ((ezcontentobject.section_id in (1))) 
                    
                    ORDER BY  path_string ASC
LIMIT 0, 3

Everything works fine if I stick with numerical fetches!?

Any ideas on what this might be?

Thanks, Steve.

http://www.oneworldmarket.co.uk

Paul Borgermans

Tuesday 07 September 2004 1:59:26 am

Hi Steve,

You need to do some more in your template: make sure characters are surrounded by quotes so the string you pass looks like ('F','G','H'). Best to do this by creating a variable that holds this string and pass it in the array filter:

{let instring=array('F','G','H')|implode(',')}
.....
attribute_filter, array(and,array('stone_product/carat','in',$instring),
.....
{/let}

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

steve walker

Wednesday 08 September 2004 8:57:09 am

Paul,

Sorry to keep bugging you about this, but I'm having trouble getting this working...

I get the implode working ok with

let clarity_in_string=array(F,G,H)|implode(hello)

but it doesnt work with

let clarity_in_string=array(F,G,H)|implode(')

Also, and this kind of makes the above less relevant - these variables are never arrays, they are only ever single values. I wondered if a combination a 'prepend' and an 'append' would do the trick...

I have

let clarity_in='('|concat($clarity,')')
let clarity_in_string=array($clarity_in)|append(')|prepend(')

as a possible way of getting say the value of clarity_in encased in quotes?

Steve

http://www.oneworldmarket.co.uk

steve walker

Monday 27 September 2004 10:15:41 am

Hi Paul B,

I wondered if you could give me some pointers on getting the alphanumeric values to work with this ala above as i cant get it working - only numbers do the job to date.

Also - I upgraded to 3.4.2 and the kernel hack doesnt work anymore - would you advise me to stay with 3.4.1 for a while so I can use your functionality, or do you intend to release 3.4.2 compatible version soon?

Thanks, Steve.

http://www.oneworldmarket.co.uk