Aller au contenu

Référence API XoopsForm

Documentation API complète pour le système de génération de formulaires XOOPS.


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 <|-- XoopsFormElementTray

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éthodeParamètresRetourDescription
addElementXoopsFormElement $element, bool $required = falsevoidAjouter élément au formulaire
getElements-arrayObtenir tous les éléments
getElementstring $nameXoopsFormElement|nullObtenir élément par nom
setExtrastring $extravoidDéfinir attributs HTML supplémentaires
getExtra-stringObtenir attributs supplémentaires
getTitle-stringObtenir titre du formulaire
setTitlestring $titlevoidDéfinir titre du formulaire
getName-stringObtenir nom du formulaire
getAction-stringObtenir URL action
render-stringRendu HTML du formulaire
display-voidAfficher le formulaire rendu
insertBreakstring $extra = ''voidInsérer coupure visuelle
setRequiredXoopsFormElement $elementvoidMarquer élément obligatoire

La classe de formulaire la plus couramment utilisée, rendu avec style sensible au thème.

<?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();

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
);

Entrée texte multi-lignes.

$textarea = new XoopsFormTextArea(
string $caption,
string $name,
mixed $value = '',
int $rows = 5,
int $cols = 50
);

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
);

Case à cocher ou groupe de cases.

$checkbox = new XoopsFormCheckBox(
string $caption,
string $name,
mixed $value = null,
string $delimeter = '&nbsp;'
);

Groupe de boutons radio.

$radio = new XoopsFormRadio(
string $caption,
string $name,
mixed $value = null,
string $delimeter = '&nbsp;'
);

Bouton soumettre, réinitialiser ou personnalisé.

$button = new XoopsFormButton(
string $caption,
string $name,
string $value = '',
string $type = 'button' // 'submit', 'reset', 'button'
);

Entrée téléchargement fichier.

$file = new XoopsFormFile(
string $caption,
string $name,
int $maxFileSize = 0
);

Champ input caché.

$hidden = new XoopsFormHidden(
string $name,
mixed $value
);

Champ entrée mot de passe.

$password = new XoopsFormPassword(
string $caption,
string $name,
int $size,
int $maxlength,
mixed $value = ''
);

Label d’affichage uniquement (pas une entrée).

$label = new XoopsFormLabel(
string $caption,
string $value
);

Groupe d’éléments multiples ensemble.

$tray = new XoopsFormElementTray(
string $caption,
string $delimeter = '&nbsp;'
);
$tray->addElement(XoopsFormElement $element, bool $required = false);
$tray->getElements();

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
end

  • XoopsObject API
  • Guides formulaires
  • Protection CSRF

#xoops #api #forms #xoopsform #reference