lock form

ugly 15 Feb, 2010
Hi
I only want my form accessible to a certain users. I know I can use getUser to obtain my users id. I would then check this against the database list of allowed users but How then do I lock out the form? Thanks for any advice
nml375 15 Feb, 2010
Hi,
Add something like this to the top of the "Form Code" (my_validate_user() would be some function to do the actual validation):
<? 
$user =& JFactory::getUser();
if (!my_validate_user($user->id)) {
  // User has no access, lockdown
  echo "You do not have permission to see this page!";
  return();
}
?>

This will prevent the form from displaying, to also prevent creative users from actually submitting the data through some faked form, add the following to serverside validation (and enable):
<?
$user =& JFactory::getUser();
if (!my_validate_user($user->id)) {
  return "You do not have permission to see this page!";
}


/Fredrik
ugly 15 Feb, 2010
Fredrik,
Thank you very much most kind, that hit's it on the head. Can I just ask you do you think it's safe to add a new field to jos_users, I know this is a core table.
nml375 15 Feb, 2010
Hi Ian,
Glad you got it working.

I would very strongly recommend against altering the structure of the jos_users table. Joomla interacts with this table using the JTableUser class, which expects a very specific structure of the table. Any changes to the database table would require that the JTableUser class is updated to match, for things to run smoothly. This in turn means you'll have to check this class every single time you update Joomla in case the file gets replaced.
It is a far better idea to use a separate table, and build a database reference to the `jos_users`.`id` field in your code.

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