TOPIC:

Validation without Required ? 9 years 9 months ago #68887

  • modernmagic's Avatar Topic Author
  • modernmagic
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 98
  • Thanks: 1
I have a multi field form in which only 4 of the 34 fields are required. The other 29 fields need to be validated only if they are filled in.

I have Required unchecked and Validation set to the appropriate library value.

Is this possible?
Joomla website design and management modernmagic.com

Please Log in or Create an account to join the conversation.

Re: Validation without Required ? 9 years 9 months ago #68951

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 808
Hi,

what validations do you need for them? Just valid_not_empty or some special ones?

Regards,
Markus

Please Log in or Create an account to join the conversation.

Re: Validation without Required ? 9 years 9 months ago #69015

  • modernmagic's Avatar Topic Author
  • modernmagic
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 98
  • Thanks: 1
not empty and email.
Joomla website design and management modernmagic.com

Please Log in or Create an account to join the conversation.

Re: Validation without Required ? 9 years 9 months ago #69109

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 808
Hi,

please go to one of your field's validation => click "custom" => click "create code framework" => paste the following code into the codebox and change FIELDNAME by the name of the field where you assign this to:
function ff_FIELDNAME_validation(element, message)
{
    var errors = '';
    for( var i = 0; i < document['ff_form<?php return $this->form;?>'].elements.length; i++ ) {
        var element = document['ff_form<?php return $this->form;?>'].elements[i];
        if( typeof element.name != 'undefined' && element.name.substr(0,6) == 'ff_nm_'  && ( element.type == 'text' || element.type == 'hidden' || element.type == 'textarea' || element.type == 'select-one') ){
           var element_name = element.name.substr(6).replace("[]","");
           if( element_name.substr(0,5) != 'email' ){
               if( ff_getElementByName(element_name).value == '' ) {
                  errors += 'Please enter '+ element_name +"\n";
               }
           } else {
               if( ff_validemail(ff_getElementByName(element_name, '')) != '' ) {
                  errors += 'Please enter a valid email address for '+ element_name +"\n";
               }
           }
        }
    }
    return errors;
}

Important for this is, that the names of the email fields start by "email", so it can recognize what validation to apply.

I also attached you a form package with the example to this message.

Regards,
Markus
Attachments:

Please Log in or Create an account to join the conversation.

Last edit: Post by TheMuffinMan.

Re: Validation without Required ? 9 years 9 months ago #69170

  • modernmagic's Avatar Topic Author
  • modernmagic
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 98
  • Thanks: 1
1. Does this work with a Radio Group?

2. I tried but it does not work. The submit button can still be clicked without first selecting a Radio Button.


3. I installed the MassValidation.zip package using the Configuration tab. How do i use it?
Joomla website design and management modernmagic.com
Attachments:

Please Log in or Create an account to join the conversation.

Re: Validation without Required ? 9 years 9 months ago #69270

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 808
Hi,

it does not work with groups, since I was assuming when "not empty" should be used, you are referring to textfields.

However, it can be extended, use the code below. This requires the group (radio/checkbox) group to have a "group" prefix in the name:
function ff_FIELDNAME_validation(element, message)
{
    var errors = '';
    for( var i = 0; i < document['ff_form<?php return $this->form;?>'].elements.length; i++ ) {
        var element = document['ff_form<?php return $this->form;?>'].elements[i];
        if( typeof element.name != 'undefined' && element.name.substr(0,6) == 'ff_nm_'  && ( element.type == 'text' || element.type == 'hidden' || element.type == 'textarea' || element.type == 'select-one') ){
           var element_name = element.name.substr(6).replace("[]","");
           if( element_name.substr(0,5) != 'email' ){
               if( ff_getElementByName(element_name).value == '' ) {
                  errors += 'Please enter '+ element_name +"\n";
               }
           } else if( element_name.substr(0,5) == 'group' ){
               if( ff_anychecked(ff_getElementByName(element_name), '') != '' ) {
                  errors += 'Please choose '+ element_name +"\n";
               }
           } else {
               if( ff_validemail(ff_getElementByName(element_name), '') != '' ) {
                  errors += 'Please enter a valid email address for '+ element_name +"\n";
               }
           }
        }
    }
    return errors;
}

The Mass Validation is a ready-to-run form to demonstrate that the code above works.

But please try the above, since the extended code is not included in the previous form example.

Regards,
Markus

Please Log in or Create an account to join the conversation.

Last edit: Post by TheMuffinMan.
  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.065 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!