Forums

Filter connection results with form

ctrlmedia 06 Apr, 2017
Hi,

I am trying to get to grips with CCV6 and I have a very basic question.
I have a connection which shows me a list of details in table view.

I would like to add a form above the table which allows me for example, to search for a name and age then after submit only show me the matching results.

I have added a form view and field view successfully above my table but I don't know whether this is the correct thing to do and how to make that form perform the search/filter on submit?

A link to a tutorial or any advice would be much appreciated.

Thanks in advance.
Regards
Max_admin 06 Apr, 2017
Hi ctrlmedia,

This is the correct way to have a "custom" search form, but if you want a search field then you could use the search view.

Your 2nd step is to build the "Where conditions" in the "Read data" function to use the passed form data, something like this may work:

Model.name:{data:name_field}
OR
Model.age:{data.age_field_name}


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ctrlmedia 07 Apr, 2017
Hi Max,

Thanks for your answer, good to know I am in the right direction but I just think there is something I am missing. It still isn't working!

I have put the below in the where conditions box, does that look correct? Should "data" be something to do with the form? the array it produces?

<?php
if ("{data.age}" !=""){
echo " Assessments.age:{data.age}";
};
?>


Plus in your code you have used {data.age_field} and {data:age_field} - I was unsure which was correct?



Kind Regards
Max_admin 07 Apr, 2017
Answer
Hi ctrlmedia,

Your code is not correct ({data.age} should be {data:age} assuming the field name is "age"), and you can't use PHP in this format, but what you need to do can be done this way:

<?php
$return = [["Assessments.name", $this->data("name")]];
if($this->data("age")){
$return[] = "OR";
$return[] = ["Assessments.age", $this->data("age")];
}
return $return;
?>


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ctrlmedia 07 Apr, 2017
Thanks again Max, that seems to have done the trick!
This topic is locked and no more replies can be posted.