Loading values into the forms

The charger() function makes it possible to specify which fields should be retrieved when the form is submitted, and also makes it possible to define the default values for such fields.

This function quite simply returns a paired table of "field name" / "default value" pairs:

function formulaire_nom_charger_dist() {
	$valeurs = array(
		"field" => "default value",
		"another field" => "",
	return $valeurs;

All the keys specified will be passed into the form’s HTML template environment. These data are then retrieved using #ENV{field} references. As soon as the form is posted, it will be the values entered by the user which take priority over the default values.

There is no need to protect the system from values entered that contain quotation marks, as SPIP already takes care of these automatically. Nonetheless, fields starting with an underscore "_" are not subject to this automatic processing, which makes them useful for passing complex variables.

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

Translations : English, français