Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi guys, again I'm here on the forum...i use your cms a lot and it's great. I'm doing a website with a database exactly like in this one on this page http://www.renegademanagement.net/Artist.aspx .

I know that for every person i can make a cloned page and list it in the page as that one...and here it's fine...but how can I program the search box to search between the range of age? let's say between 22 and 45?

I know pretty much nothing about php...is this possible with couch??

thanks a lot like usually you guys are the best :D
Hi,

This is the functionality that you wish to have -
0.jpg
0.jpg (87.7 KiB) Viewed 5919 times

To mimic the functionality in Couch, we can use the regular cms:pages tag.
The 'pages' tag supports fetching pages based on the values contained within the editable regions.
The parameter for this is custom_field.

So, let us suppose that your template, in addition to the other regions, has two editable regions that we'd like to use in searching for pages - my_age and my_type.
This is how we declare them -
Code: Select all
   <cms:editable name="my_age" label="Age"
      search_type='integer'
      validator='non_zero_integer'
      required='1'
      width='155'
      type="text" />
                   
   <cms:editable name="my_type" label="Type"
      opt_values='ANY  | ACTORS | MODELS | YOUTH  | TALENT | INTERNATIONAL'
      type="dropdown" />

Notice how we have declared the 'my_age' region with the 'search_type' of 'integer'. this is because age would be a numeric value and it is always efficient to search on numeric values.

Now we can fetch in pages containing specific values in the two fields this way -
Code: Select all
<cms:pages custom_field="my_age>=18 | my_age<=86 | my_type==ACTORS" >
   <h2><cms:show k_page_title /></h2>
   <cms:show my_age /> <br />
   <cms:show my_type /> <br />
   <hr />
</cms:pages>

In the example above, the 'pages' tag will only fetch in pages that have 'my_age' between 18 and 86 and with the 'my_type' of 'ACTORS'.

This much should have been straightforward.

However, instead of hardcoding the search parameters into the 'pages' tag, as we did in the example above, we wish to dynamically vary it according to whatever values a visitor has chosen.

To do so, we can create and display a web-form on the page. The visitor can choose the desired values and submit the form.
We can then pass the submitted values on to the 'pages' tag.

A common method of passing the selected parameters back to the script is via the querystring.
The website you mentioned is also doing the same. Notice how the selected values are being passed -
2.gif
2.gif (1.12 KiB) Viewed 5919 times

We'll do the same.
Let us create a form first -
Code: Select all
<cms:form name="quicksearch" id="quicksearch" anchor='0'>
   AGE:
   <cms:input type="dropdown"
       name="agef"
       opt_values="ALL<cms:repeat startcount='1' count='100'>|<cms:show k_count /></cms:repeat>"
   />
   to:
   <cms:input type="dropdown"
       name="ageto"
       opt_values="ALL<cms:repeat startcount='1' count='100'>|<cms:show k_count /></cms:repeat>"
   />
   TYPE:
   <cms:input type="dropdown"
       name="type"
       opt_values="ANY  | ACTORS | MODELS | YOUTH  | TALENT | INTERNATIONAL"
   />
   <cms:input type="submit" value="Find!" name="submit"/>
</cms:form>

It is rather bland but will serve our demo purpose -
1.jpg
1.jpg (6.06 KiB) Viewed 5919 times

Upon successful submission of the form we'll gather the submitted values and create a 'search string' of the format that 'pages' tag accepts.
The modified form now becomes -
Code: Select all
<cms:form name="quicksearch" id="quicksearch" anchor='0'>
   <cms:if k_success >
      <cms:if frm_agef ge '1' && frm_agef le '100' >
         <cms:set my_search_str="<cms:concat my_search_str ' | my_age>=' frm_agef />"  scope='global'/>
      </cms:if>
     
      <cms:if frm_ageto ge '1' && frm_ageto le '100' >
         <cms:set my_search_str="<cms:concat my_search_str ' | my_age<=' frm_ageto />"  scope='global'/>
      </cms:if>   

      <cms:if frm_type = 'ACTORS' || frm_type = 'MODELS' || frm_type = 'YOUTH' || frm_type = 'TALENT' || frm_type = 'INTERNATIONAL' >
         <cms:set my_search_str="<cms:concat my_search_str ' | my_type==' frm_type />"  scope='global'/>
      </cms:if>
   </cms:if>
   
   AGE:
   <cms:input type="dropdown"
       name="agef"
       opt_values="ALL<cms:repeat startcount='1' count='100'>|<cms:show k_count /></cms:repeat>"
   />
   to:
   <cms:input type="dropdown"
       name="ageto"
       opt_values="ALL<cms:repeat startcount='1' count='100'>|<cms:show k_count /></cms:repeat>"
   />
   TYPE:
   <cms:input type="dropdown"
       name="type"
       opt_values="ANY  | ACTORS | MODELS | YOUTH  | TALENT | INTERNATIONAL"
   />
   <cms:input type="submit" value="Find!" name="submit"/>
</cms:form>

Notice how in the 'success' block we check if proper values have been submitted and then append the values to a my_search_str variable that is in global scope (because we'll use it outside the form)

Outside the form, we'll place the regular 'pages' loop but this time we'll set its 'custom_field' to the 'my_search_str' we crafted above -
Code: Select all
<cms:pages custom_field=my_search_str >
   <h2><cms:show k_page_title /></h2>
   <cms:show my_age /> <br />
   <cms:show my_type /> <br />
   <hr />
</cms:pages>

Of course, you can display the records found any way you desire.

We can make a few additions to show the number of pages found -
Code: Select all
<cms:pages custom_field=my_search_str >
   <cms:if k_paginated_top >
      <cms:show k_total_records /> Results Found <br />
      <cms:set flag_records_found='1' scope='global'/>
   </cms:if>
   
   <h2><cms:show k_page_title /></h2>
   <cms:show my_age /> <br />
   <cms:show my_type /> <br />
   <hr />
</cms:pages>

<cms:if flag_records_found!='1' >
    0 Results Found <br />
</cms:if>

And that is it.

The complete code for the template is here -
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<!-- Mimicking functionality of http://www.renegademanagement.net/Artist.aspx -->
<cms:template title='Search2' clonable='1'>

   <cms:editable name="my_age" label="Age"
      search_type='integer'
      validator='non_zero_integer'
      required='1'
      width='155'
      type="text" />
                   
   <cms:editable name="my_type" label="Type"
      opt_values='ANY  | ACTORS | MODELS | YOUTH  | TALENT | INTERNATIONAL'
      type="dropdown" />

</cms:template>

<cms:form name="quicksearch" id="quicksearch" anchor='0'>
   <cms:if k_success >
      <cms:if frm_agef ge '1' && frm_agef le '100' >
         <cms:set my_search_str="<cms:concat my_search_str ' | my_age>=' frm_agef />"  scope='global'/>
      </cms:if>
     
      <cms:if frm_ageto ge '1' && frm_ageto le '100' >
         <cms:set my_search_str="<cms:concat my_search_str ' | my_age<=' frm_ageto />"  scope='global'/>
      </cms:if>   

      <cms:if frm_type = 'ACTORS' || frm_type = 'MODELS' || frm_type = 'YOUTH' || frm_type = 'TALENT' || frm_type = 'INTERNATIONAL' >
         <cms:set my_search_str="<cms:concat my_search_str ' | my_type==' frm_type />"  scope='global'/>
      </cms:if>
   </cms:if>
   
   AGE:
   <cms:input type="dropdown"
       name="agef"
       opt_values="ALL<cms:repeat startcount='1' count='100'>|<cms:show k_count /></cms:repeat>"
   />
   to:
   <cms:input type="dropdown"
       name="ageto"
       opt_values="ALL<cms:repeat startcount='1' count='100'>|<cms:show k_count /></cms:repeat>"
   />
   TYPE:
   <cms:input type="dropdown"
       name="type"
       opt_values="ANY  | ACTORS | MODELS | YOUTH  | TALENT | INTERNATIONAL"
   />
   <cms:input type="submit" value="Find!" name="submit"/>
</cms:form>

<cms:pages custom_field=my_search_str >
   <cms:if k_paginated_top >
      <cms:show k_total_records /> Results Found <br />
      <cms:set flag_records_found='1' scope='global'/>
   </cms:if>
   
   <h2><cms:show k_page_title /></h2>
   <cms:show my_age /> <br />
   <cms:show my_type /> <br />
   <hr />
</cms:pages>

<cms:if flag_records_found!='1' >
    0 Results Found <br />
</cms:if>


<?php COUCH::invoke(); ?>


Hope this helps.
Do let me know.
I have to tell that this just the most amazing , helpful and efficient forum I've ever been in and the most efficient program i've ever use....

Your answer was amazing and definitely saved my life and face with my client.

I don't know what to say if not a thanks :)

really....unfortunately i'm just a designer so i can't be really helpful with anything but you guys need anything just let me know

Thanks again
Glad we could help :)
4 posts Page 1 of 1
cron