Forums

DB Read Conditions ignored

batvink 16 Feb, 2016
Hi,

I am trying to read a local database table (a_category)in the On Submit event.
I want to retrieve records where a_category.name is the same as a value in the form.
My DB Read has a model Id of Data1.
Therefore I have added a condition to the read:

 < ?php
return array('Data1.name' => $form->data['name']);
?>


If a record is found I add a $form->errors[] entry and run the event loop.
It ALWAYS finds a record (when it shouldn't) and the PHP conditions code is displayed on the form also.

Data Array
Array
(
    [option] => com_chronoforms5
    [chronoform] => New_Category
    [event] => submit
    [name] => Cat1
    [description] => Cat1
    [userid] => 0
    [submit] => Submit
    [Data1] => Array
        (
            [qid] => 1
            [name] => Test
            [description] => Test
            [public] => 1
            [standard] => 0
            [created] => 2016-02-13 14:55:08
            [userid] => 814
        )

)
Array
(
)
Errors
Array
(
)
Debug Info
Array
(
    [8] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Data1`.`qid` AS `Data1.qid`, `Data1`.`name` AS `Data1.name`, `Data1`.`description` AS `Data1.description`, `Data1`.`public` AS `Data1.public`, `Data1`.`standard` AS `Data1.standard`, `Data1`.`created` AS `Data1.created`, `Data1`.`userid` AS `Data1.userid` FROM `a_category` AS `Data1`
                        )

                )

        )

)
GreyHead 16 Feb, 2016
Hi batvink,

It looks as though you have a space in < ?php - if you do please remove it.

Bob
batvink 16 Feb, 2016
You are right.
The reason? I copied and pasted the example below the conditions box! This has a space in it.

conditions array returned using PHP in array format, e.g: < ?php return array('field' => 'value'); ?>



Lesson learned!
Thanks again.
GreyHead 16 Feb, 2016
Hi batvink,

Ah sorry - I don't think that I have any way to fix that one :-( It will need to wait for Max.

Bob
This topic is locked and no more replies can be posted.