Forums

DB Read / display only to logged in user

mduda 22 May, 2016
Hi Bob,

I am adjusting a form to allow both logged in users as well as guests access.
[attachment=0]cf_db_read.png[/attachment]

Issue is that when a public user accesses the form, it lists all data submitted by guest users.
[attachment=1]cf_debug_guest.png[/attachment]

Any suggestions on how to have this custom code which is displayed in the designer tab not show to guest/public users?
[attachment=2]cf_custom_code_designer.png[/attachment]
GreyHead 22 May, 2016
Answer
Hi mduda,

Does it work if you change the change the Conditions code like this:
<?php
$juser = \JFactory::getUser();
if ( $juser->id > 0 ) {
  return array( 'user_id' => $juser->id );
} else {
  return array( 'user_id' => '999999' );
}
?>

Bob

[[>> Later : fixed missing } <<]]
mduda 22 May, 2016
When I place the new code into the conditions of the DB Read, it actually pull the entire table to display. When I use the original code (without the 'else'), it pulls only the info entered from the computer/ip.

Any ideas on how to make the 'else' statement return "" ?
GreyHead 22 May, 2016
Hi mduda,

Hmmm . . . the 1 = 2 version works in MySQL but apparently not here. I've edited the post, please try the updated version.

Bob
mduda 22 May, 2016
Still showing all of the data with the new code
GreyHead 22 May, 2016
Hi mduda,

Please turn on the Debugger and post the output here - I'm looking for the MySQL query that is created with this as the WHERE clause. it should be WHERE `user_id` = '999999' or something similar.

Bob
mduda 22 May, 2016
Wooohooo! Thanks so much Bob! It's working🙂 Used your code...added the '}' after the second return array, and all is good!!! You rock:)
GreyHead 23 May, 2016
Hi Mduda,

Sorry about the typo . . . :-( Good to hear that it's working for you now :-)

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