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) ?
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.
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.
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.