J'utilise Joomla! 3.4 validation du formulaire principal et il semble fonctionner parfaitement, mais les messages d'erreur ajoutés à l'alerte sont vierges; par conséquent, je ne vois pas quelle est l'erreur.
Qu'est-ce que je fais mal?
Voici mon manifeste XML JForm:
<?xml version="1.0" encoding="utf-8"?>
<form class="form-validate">
<fieldset name="lead" label="Apply now!" description="Complete the form below to receive your unique code">
<field name="name" type="text" hiddenLabel="true" class="input-block validate required" hint="Name"
description="Your full name" label="Name" filter="string" required="true" />
<field name="surname" type="text" hiddenLabel="true" class="input-block validate required" hint="Surname"
description="JGLOBAL_FIELD_ID_DESC" filter="string" required="true" />
<field name="cellphone" type="text" hiddenLabel="true" class="input-block validate required"
hint="Cellphone number" required="true" />
<field name="email" type="text" hiddenLabel="true" class="input-block validate required validate-email"
hint="Email address" filter="string" required="true" />
<field name="membership_number" type="text" hiddenLabel="true" class="input-block validate required"
hint="Membership number"/>
</fieldset>
</form>
Et mon formulaire HTML est rendu avec ceci:
<form id="pb-apply-lead-form" action="<?php echo JRoute::_('index.php'); ?>" method="post" class="form-validate">
<fieldset class="pb-apply-lead-fieldset">
<?php
# Load keep-alive, will prevent form from expiring
JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
if (J33)
JHtml::_('behavior.formvalidation'); // J!3.3
if (J34)
JHtml::_('behavior.formvalidator'); // J!3.4
/** @var JForm $lead_form */
$lead_form = JForm::getInstance('lead', JPATH_COMPONENT . '/models/forms/lead.xml');
$fieldset = $lead_form->getFieldsets();
?>
<div class="pb-title-container">
<h3><?php echo $fieldset['lead']->label; ?></h3>
<h4><?php echo $fieldset['lead']->description; ?></h4>
</div>
<div class="form-fields">
<div class="row">
<?php
# Render out fieldset, use override for fields provided in layouts
echo $lead_form->renderFieldset('lead');
?>
</div>
</div>
<div class="form-button">
<input type="submit" name="submit" value="<?php echo JText::_('COM_BULKBUYER_VIEW_APPLY_FORM_BUTTON_SUBMIT'); ?>" class="validate btn btn-primary"/>
<input type="hidden" name="option" value="com_bulkbuyer"/>
<input type="hidden" name="task" value="apply.submitlead"/>
<input type="hidden" name="return" value="<?php echo JUri::current(); ?>"/>
<input type="hidden" name="id" value="<?php echo $item->id; ?>"/>
<?php echo JHtml::_('form.token'); ?>
</div>
</fieldset>
</form>
Merci d'avance pour votre aide.
Le problème est que vous n'avez pas défini les messages d'erreur. Par conséquent, aucun message d'erreur ne s'affiche. Vous devez inclure:
message = "Ce champ est obligatoire!"
Vous utilisiez description = "" et cela est indiqué dans les info-bulles du champ.
Donc, votre code devient:
<?xml version="1.0" encoding="utf-8"?>
<form class="form-validate">
<fieldset name="lead" label="Apply now!" message="Complete the form below to receive your unique code">
<field name="name" type="text" hiddenLabel="true" class="input-block validate required" hint="Name"
message="Your full name" label="Name" filter="string" required="true" />
<field name="surname" type="text" hiddenLabel="true" class="input-block validate required" hint="Surname"
message="JGLOBAL_FIELD_ID_DESC" filter="string" required="true" />
<field name="cellphone" type="text" hiddenLabel="true" class="input-block validate required"
hint="Cellphone number" required="true" />
<field name="email" type="text" hiddenLabel="true" class="input-block validate required validate-email"
hint="Email address" filter="string" required="true" />
<field name="membership_number" type="text" hiddenLabel="true" class="input-block validate required"
hint="Membership number"/>
</fieldset>
</form>
Voir: https://docs.joomla.org/Text_form_field_type
Pour plus d’utilisation sur les champs de texte JForm.