Authorise the display or hiding of a form

Forms are displayed by default, but it is possible to restrict this display depending on certain assigned authorising data.

Two possibilities exist:

  • either you don’t want to display the formula at all, so then return a false :
    function formulaire_nom_charger_dist() {
    	$valeurs = array();
    	if (!autoriser("webmestre")) {
    		return false;
    	}
    	return $valeurs;
    }
    
  • or simple hide a part of the form (often the editable part) by using the "editable" variable, which is then handled in the form template:
    function formulaire_nom_charger_dist() {
    	$valeurs = array();
    	if (!autoriser("webmestre")) {
    		$valeurs['editable'] = false;
    	}
    	return $valeurs;
    }
    

Example

The "Accès restreint" (limited access) plugin has a form for assigning zones to an author; it passes the fields to be retrieved and their default values into the environment: the zone identifier, the connected author, and the author to be assigned to the zone. In addition, if the author does not have adequate rights, the "editable" variable is passed as false.

function formulaires_affecter_zones_charger_dist($id_auteur){
	$valeurs = array(
		'zone'=>'',
		'id_auteur'=>$id_auteur,
		'id'=>$id_auteur
	);
	include_spip('inc/autoriser');
	if (!autoriser('affecterzones','auteur',$id_auteur)){
		$valeurs['editable'] = false;
	}
	return $valeurs;
}

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français