2

I'm using Joomla! 3.4 core form validation and it seems to fire perfectly, but the error messages added to the alert are blank, hence I cannot see what the error is.

What am I doing wrong?

Here is my JForm XML manifest:

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

And my form HTML is rendered with this:

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

Thanks in advance for any help.

2

The problem is you haven't set the Error messages, so no error message is shown. You need to include:

message="This field is required!"

You were using description="" and this is shown in the tooltips of the field.

So your code becomes:

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

See: https://docs.joomla.org/Text_form_field_type

For more usage on JForm Text fields.

  • Thank you, very much. Just for interest, how would I invoke the standard error messages? – Anriëtte Myburgh Nov 13 '15 at 9:29
  • Another thing...I added the message="" atrribute and the messages are still blank when outputted to the <div class="system-message-container">. I'm sure I'm missing something. – Anriëtte Myburgh Nov 13 '15 at 10:02
  • I found I had this problem when I was showing a field without an accompanying label tag. When there was just an input, the system-message-container was blank, but when there was a label and a message, it was ok. – AndyGaskell Aug 19 '16 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.