Radiobutton as required field

resolved (4 posts) (2 voices)

  1. juwe
    Member

    I have a long formular to let users sign up to a conference.
    There are some radiobuttons and I want them to use as required fields.
    How can I do this?

    Posted 1 year ago #
  2. Elliott
    Support

    Hello juwe,

    Just to make sure I understand correctly. You added some radio buttons to the contact form and you want to make them required fields?

    Posted 1 year ago #
  3. juwe
    Member

    Hi Elliott,

    that's exactly what I want.

    Posted 1 year ago #
  4. Elliott
    Support

    This is a little complex juwe. You will want to add the class "requiredField" to your radio button elements and then open up js/custom.js and on lines 261 - 276 you can find the validation code,

    jQuery('.requiredField').each(function() {
    	if(jQuery.trim(jQuery(this).val()) == '') {
    		var labelText = jQuery(this).prev('label').text();
    		//jQuery(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
    		jQuery(this).addClass('inputError');
    		hasError = true;
    	} else if(jQuery(this).hasClass('email')) {
    		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    		if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
    			var labelText = jQuery(this).prev('label').text();
    			//jQuery(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
    			jQuery(this).addClass('inputError');
    			hasError = true;
    		}
    	}
    });

    You can try it by itself but you might have to add a section for your radio buttons.

    Posted 1 year ago #

Reply

You must log in to post.

Construct WordPress Theme
Construct wordpress theme
Myriad WordPress Theme
Myriad wordpress theme
Method WordPress Theme
Method wordpress theme
Fusion WordPress Theme
Fusion wordpress theme
Elegance WordPress Theme
Elegance wordpress theme
Echelon WordPress Theme
Echelon wordpress theme
Dejavu WordPress Theme
Dejavu wordpress theme
Modular WordPress Theme
Modular wordpress theme