DB Read user_id

Prevent DB Read from auto-filling forms for unregistered users.

Overview

The DB Read action was returning previous user data for guest users instead of an empty form.
Modify the DB Read code to check if the user is logged in; return user data only for registered users and an empty array for guests.

Answered
hc hcohl 18 Feb, 2017
I created a form with DBRead:
<?php
$user = JFactory::getUser();
return array("user_id" => $user->get("id"));
?>

Now the problem is, if a not registered user opens the form, he gets information of another (not registered) user filled the form before.
How can I give the not registered users an emty form?
Thanks for help.
Gr GreyHead 18 Feb, 2017
Hi hcohl,

Please try this
<?php
$user = \JFactory::getUser();
if ( $user->id > 0 ) {
  return array( 'user_id' => $user->id );
} else {
  return array( ": 'AAA' = 'ZZZ' " );
}
?>
That should return an empty array for a guest.

Bob
hc hcohl 19 Feb, 2017
Hallo Bob,
thank you for your answer.
But this returns error 1054 - Unknown column 'Data.AAA'.
What do I have to set for "AAA" and "ZZZ"?
HC Ohl
Gr GreyHead 19 Feb, 2017
Answer
Hi hcohl,

Sorry, Not thinking clearly - I've updated this line
return array( ": 'AAA' = 'ZZZ' " );
you just need something there that returns no records.

Bob
hc hcohl 19 Feb, 2017
Thank you Bob - it works.

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