Référence API XoopsForm
Documentation API complète pour le système de génération de formulaires XOOPS.
Hiérarchie des classes
Section intitulée « Hiérarchie des classes »classDiagram class XoopsForm { <<abstract>> #string $title #string $name #string $action #string $method #array $elements #string $extra #bool $required +addElement(element, required) +getElements() +getElement(name) +setExtra(extra) +render() +display() }
class XoopsThemeForm { +render() }
class XoopsSimpleForm { +render() }
class XoopsTableForm { +render() }
XoopsForm <|-- XoopsThemeForm XoopsForm <|-- XoopsSimpleForm XoopsForm <|-- XoopsTableForm
class XoopsFormElement { <<abstract>> #string $name #string $caption #string $description #string $extra #bool $required +getName() +getCaption() +setCaption(caption) +getDescription() +setDescription(desc) +isRequired() +setRequired(required) +render() }
XoopsFormElement <|-- XoopsFormText XoopsFormElement <|-- XoopsFormTextArea XoopsFormElement <|-- XoopsFormSelect XoopsFormElement <|-- XoopsFormCheckBox XoopsFormElement <|-- XoopsFormRadio XoopsFormElement <|-- XoopsFormButton XoopsFormElement <|-- XoopsFormFile XoopsFormElement <|-- XoopsFormHidden XoopsFormElement <|-- XoopsFormLabel XoopsFormElement <|-- XoopsFormPassword XoopsFormElement <|-- XoopsFormElementTrayXoopsForm (Base abstraite)
Section intitulée « XoopsForm (Base abstraite) »Constructeur
Section intitulée « Constructeur »public function __construct( string $title, // Titre du formulaire string $name, // Attribut name du formulaire string $action, // URL action du formulaire string $method = 'post', // Méthode HTTP bool $addToken = false // Ajouter token CSRF)Méthodes
Section intitulée « Méthodes »| Méthode | Paramètres | Retour | Description |
|---|---|---|---|
addElement | XoopsFormElement $element, bool $required = false | void | Ajouter élément au formulaire |
getElements | - | array | Obtenir tous les éléments |
getElement | string $name | XoopsFormElement|null | Obtenir élément par nom |
setExtra | string $extra | void | Définir attributs HTML supplémentaires |
getExtra | - | string | Obtenir attributs supplémentaires |
getTitle | - | string | Obtenir titre du formulaire |
setTitle | string $title | void | Définir titre du formulaire |
getName | - | string | Obtenir nom du formulaire |
getAction | - | string | Obtenir URL action |
render | - | string | Rendu HTML du formulaire |
display | - | void | Afficher le formulaire rendu |
insertBreak | string $extra = '' | void | Insérer coupure visuelle |
setRequired | XoopsFormElement $element | void | Marquer élément obligatoire |
XoopsThemeForm
Section intitulée « XoopsThemeForm »La classe de formulaire la plus couramment utilisée, rendu avec style sensible au thème.
Utilisation
Section intitulée « Utilisation »<?php$form = new XoopsThemeForm( 'Enregistrement utilisateur', 'registration_form', 'register.php', 'post', true // Inclure token CSRF);
$form->addElement(new XoopsFormText('Nom d\'utilisateur', 'uname', 25, 255, ''), true);$form->addElement(new XoopsFormPassword('Mot de passe', 'pass', 25, 255), true);$form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
echo $form->render();Éléments de formulaires
Section intitulée « Éléments de formulaires »XoopsFormText
Section intitulée « XoopsFormText »Entrée texte sur une seule ligne.
$text = new XoopsFormText( string $caption, // Texte label string $name, // Attribut name int $size, // Largeur d'affichage int $maxlength, // Max caractères mixed $value = '' // Valeur par défaut);XoopsFormTextArea
Section intitulée « XoopsFormTextArea »Entrée texte multi-lignes.
$textarea = new XoopsFormTextArea( string $caption, string $name, mixed $value = '', int $rows = 5, int $cols = 50);XoopsFormSelect
Section intitulée « XoopsFormSelect »Liste déroulante ou sélection multiple.
$select = new XoopsFormSelect( string $caption, string $name, mixed $value = null, int $size = 1, // 1 = dropdown, >1 = listbox bool $multiple = false);XoopsFormCheckBox
Section intitulée « XoopsFormCheckBox »Case à cocher ou groupe de cases.
$checkbox = new XoopsFormCheckBox( string $caption, string $name, mixed $value = null, string $delimeter = ' ');XoopsFormRadio
Section intitulée « XoopsFormRadio »Groupe de boutons radio.
$radio = new XoopsFormRadio( string $caption, string $name, mixed $value = null, string $delimeter = ' ');XoopsFormButton
Section intitulée « XoopsFormButton »Bouton soumettre, réinitialiser ou personnalisé.
$button = new XoopsFormButton( string $caption, string $name, string $value = '', string $type = 'button' // 'submit', 'reset', 'button');XoopsFormFile
Section intitulée « XoopsFormFile »Entrée téléchargement fichier.
$file = new XoopsFormFile( string $caption, string $name, int $maxFileSize = 0);XoopsFormHidden
Section intitulée « XoopsFormHidden »Champ input caché.
$hidden = new XoopsFormHidden( string $name, mixed $value);XoopsFormPassword
Section intitulée « XoopsFormPassword »Champ entrée mot de passe.
$password = new XoopsFormPassword( string $caption, string $name, int $size, int $maxlength, mixed $value = '');XoopsFormLabel
Section intitulée « XoopsFormLabel »Label d’affichage uniquement (pas une entrée).
$label = new XoopsFormLabel( string $caption, string $value);XoopsFormElementTray
Section intitulée « XoopsFormElementTray »Groupe d’éléments multiples ensemble.
$tray = new XoopsFormElementTray( string $caption, string $delimeter = ' ');
$tray->addElement(XoopsFormElement $element, bool $required = false);$tray->getElements();Diagramme flux du formulaire
Section intitulée « Diagramme flux du formulaire »sequenceDiagram participant User participant Browser participant Form participant Security participant Handler participant Database
User->>Browser: Remplir formulaire Browser->>Form: Soumettre POST Form->>Security: Valider token CSRF
alt Token invalide Security-->>Browser: Erreur : Token invalide Browser-->>User: Afficher erreur else Token valide Security->>Handler: Traiter données Handler->>Handler: Valider entrée
alt Validation échouée Handler-->>Browser: Afficher formulaire avec erreurs Browser-->>User: Afficher erreurs else Validation réussie Handler->>Database: Enregistrer données Database-->>Handler: Succès Handler-->>Browser: Redirection Browser-->>User: Message succès end endDocumentation connexe
Section intitulée « Documentation connexe »- XoopsObject API
- Guides formulaires
- Protection CSRF
#xoops #api #forms #xoopsform #reference