Pages

Pages

Previous: Creating a custom success page Up to Contents Next: Appendix 1: Download the source code

How to build submission forms using Xataface

Jump:

A submission form (a form for users to submit information into a database) is a very common use-case for Xataface. This tutorial teaches you how to do it the right way.

Disabling unnecessary features

The submission form still has a lot of extra buttons to click on (the details, list, and find tabs), and other distracting features (e.g. the search form) that need to be disabled.

Submission forms should be simple and fool-proof.  The user should be able to to one thing: submit the form.  All other features, links, and buttons should be removed.  Xataface allows you to disable many features.  Features can be enabled or disabled individually in the [_prefs] section of the conf.ini file.   However doing this does not allow you to conditionally disable features for some users but not for others.  We still want the administrator to have access to all of these features.  It is only public users that should not see these.  For this sort of conditional preferences, we will implement the getPreferences() method of the Application's delegate class.

Implementing getPreferences()

We will implement our getPreferences() method as follows:

function getPreferences(){
$app =& Dataface_Application::getInstance();
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
if ( $user && isAdmin($user->val('role')) ){
return array();

} else {
return array(
'show_result_stats'=>0,
'show_jump_menu'=>0,
'show_result_controller'=>0,
'show_table_tabs'=>0,
'show_actions_menu'=>0,
'show_tables_menu'=>0,
'show_search'=>0,
'show_record_actions'=>0,
'show_recent_records_menu'=>0,
'show_record_tabs'=>0,
'show_record_tree'=>0,
'show_bread_crumbs'=>0);

}
}

Notes

  • We make use of our isAdmin() function (that we define in another file) to see if the current user is an administrator.  If so, we return an empty array (which signifies that no changes are to be made to the preferences).
  • If the user is not logged in, we disable nearly all of the features that can be disabled.f
  • Note that this method MUST return an array no matter what.  Even if it is an empty array.  This is a common pit-fall, as it is tempting to only deal with the case you want to override and forget about the rest of the cases.
  • Notice the use of if ($user and ... $user->val() ...)
    Before calling any methods on the $user object, make sure it exists - it could be null.  Calling methods on a null object will result in fatal errors (not fun).
  • Read more about the Dataface_Application class or the Dataface_AuthenticationTool class.



Previous: Creating a custom success page Up to Contents Next: Appendix 1: Download the source code
blog comments powered by Disqus
Powered by Xataface
(c) 2005-2024 All rights reserved