Chronoforms7 "Read Data" Action - php conditions

How to use optional WHERE conditions in ChronoForms7 Read Data action.

Overview

The issue arises when trying to create dynamic database queries where conditions should only apply if a form field has a value.
Use the PHP conditions setting to programmatically build and return a conditions array based on form input values, enabling optional filtering.

Answered
ChronoForms v7
ma mayergreenberg259 17 Nov, 2023
In chronoforms 7, there is a 'Read Data' acton.
Inside the 'Read Data' action there is an advanced setting called "php conditions" which lets one "add where conditions to the sql statement using php".
Can someone show me how this works? I have not been able to get it to work.
My final goal is to use the php to read a form's input value, and use that value in the where condition. If someone could show me how to do that, it would be much appreciated.
Thank you.
Max_admin Max_admin 18 Nov, 2023
why PHP ? you can use {data:field_name} in normal conditions
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ma mayergreenberg259 19 Nov, 2023
Thank you so much. That worked.

Can you answer my other question at https://www.chronoengine.com/forums/topics/view/110871/how-can-i-link-more-tables-in-the-read-data-action-in-a-chronoconnectivity7-form#p402103
ma mayergreenberg259 19 Nov, 2023
I also have another question:
Is it possible to make the where condition optional?
I would like to have a form with some inputs, which, when submitted, query's the database with the inputs being used in the where conditions.
But I only want the where clause to limit the search when the input in the form is filled out. So I want the where clause to use the input when the input has a value, but when there is no value I want the where clause to be ignored and just return all values. Is this possible?
Max_admin Max_admin 19 Nov, 2023
To have conditions optional you need to use PHP conditions and build the conditions array based on the data you need, conditions are returned as an array:
return [["column1", "value1", "="],["column2", "value2", "!="]];
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ma mayergreenberg259 21 Nov, 2023
Answer
It hasn't worked for me. Here is how I did it:
return [["VoidPayments.Reason", "22222", "="],["CreditCardPayment.CreditCardId", "1", "="]];

VoidPayments and CreditCardPayment are the tables and Reason and CreditCardId are the columns in their tables.

Is there another syntax I should be using?

Thank you
Max_admin Max_admin 21 Nov, 2023
enable the form debug and check the generated SQL, does it show the conditions ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ma mayergreenberg259 21 Nov, 2023
1 Likes
Actually it started working. Thank you so much.
How do I reference the form field data within the php conditions?
Max_admin Max_admin 21 Nov, 2023
$this->data("field_name")


and you can other actions data vars using

$this->get("action_name")
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.