We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Dynamic parameters and exact matching

Development and Programming

lydie_t's avatar
lydie_t
3 posts
5 years ago
lydie_t's avatar lydie_t

On my first template, I have this form :

<form action="{path='product/book'}">

  <input type="text" name="search:book-code">
  
  <input type="submit" value="OK">
  
</form>

On my second template, I retreive entries with dynamic_parameters :

{exp:channel:entries channel="book" dynamic_parameters="search:book-code"}

        <h1>{book-code}</h1>

{/exp:channel:entries}

Let’s assume that I have an entry with the value 123 in a book-code custom field :

— If I enter 123 in the form input, I get the the entry. That’s fine.

— But if I enter 1, I also get the entry. And that’s the problem.

How do I retreive the entry only if the input value matches exactly the book-code field value (123) ?

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
5 years ago
Robin Sowell's avatar Robin Sowell

Hrm- do you need a broad solution or just one that would work in the exact circumstances above? Because in the above, I wouldn’t use dynamic parameters- I’d just pass the number in the url and use this parameter:

search:book_code="={segment_3}"

Making sure dynamic=”no”.

       
lydie_t's avatar
lydie_t
3 posts
5 years ago
lydie_t's avatar lydie_t

I am looking for a broad solution. I have set dynamic to “no“.

Using a {segment_x} parameter would indeed permit to use the “search:field_name“ “exact matching“ method.

Is there a way to send the book-code input value as a URL segment ? I am not sure that this is possible only by using ee tags.

To be a little more precise about the aim to reach : the visitor has to enter a code manually (ie: 123, 589, 888, etc.) in the input. If the entered code matches exactly the book-code field value of a channel entry, the corresponding entry should be displayed. On the contrary, an error message should be displayed.

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
5 years ago
Robin Sowell's avatar Robin Sowell

Hrm- well, you could get the value in as a query string easy enough via <form action="{path='product/book'}" method="get"> but then you’re dealing with getting it out of the query string.

I know I’ve done this with javascript before. Something like this: https://stackoverflow.com/questions/22451513/javascript-to-open-a-url-the-text-input-by-user

Bonus if you make a ‘get’ fallback for js disabled, but I’m not sure it’s worth the effort on that one.

       
lydie_t's avatar
lydie_t
3 posts
5 years ago
lydie_t's avatar lydie_t

Hi Robin, thank you for your help. The solution you mentioned is a way to obtain the desired result.

In the meantime, I have managed to solve the problem by sending the input data through the form with method="get". Then I compared the value with those stored in database using the DB Class. This displays the corresponding book. Or it shows an error message if the value matches nothing.

That said, this is really sad that it is not possible to associate dynamic parameters with exact matching using EE templating language. It could be a great improvement to make interactity very simple in EE.

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
5 years ago
Robin Sowell's avatar Robin Sowell

I’m glad you’ve got a workaround using GET. And it does make for a good feature request to add some way of using the search parameter in any of the allowed ways, even when dynamic. We just need a good way to specify which type of search to do.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.