• SSmeredith

    (@ssmeredith)


    Hi There!

    I would like to use the review form in a modal. The problem is that it needs to stay open if the user clicks submit or gets an error, like missing a required field etc..

    This was a similar issue with Gravity forms but once they added the Ajax option, that was fixed.

    So I am wondering if you have this option or plan on implementing it?

    Thank you for the plugin!!

    https://wordpress.org/plugins/rich-reviews/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Nuanced Media

    (@nuanced-media)

    SSmeredith,

    This is in the works. It has been long requested functionality. I will let you know when we have it completed and an update ready.

    Thanks,
    Charlie Maxwell
    [NM_Developer]

    Thread Starter SSmeredith

    (@ssmeredith)

    Thanks so much!!

    Any update on this? Ajax submission would be incredibly useful.

    Ajax functionality needs to be added to the core of this plugin, but in the meantime this code will cause validation errors to display without reloading the page.

    The jQuery Validate plugin is needed for this code to work.

    // add "required" attribute to the inputs and textareas that should be required
    $('.rr_review_form .rr_required + .rr_form_input > input, .rr_review_form .rr_required + .rr_form_input > textarea').attr('required', 'required');
    
    // [IF USING STARS] add an input so stars can be validated
    $('.rr_stars_container').append('<input type="checkbox" name="input_stars" style="opacity: 0;">');
    
    // [IF USING STARS] add a function to remove error when stars are selected
    $('.rr_stars_container').click(function() {
    	if ($('.rr_stars_container').find('.glyphicon-star').length > 0) {
    		$('input[name="input_stars"]').removeClass('error');
    		$('label#input_stars-error').hide();
    	}
    });
    
    // [IF USING STARS] add a method to the validate plugin to check for a stars rating
    $.validator.addMethod("selectStars", function(value, element) {
    	return $('.rr_stars_container').find('.glyphicon-star').length > 0;
    }, "Please rate this product.");
    
    // validate the form
    $('.rr_review_form').validate({
    	// [IF USING STARS] add a method to the validate plugin to check for a stars rating
    	rules : {
    		input_stars : { selectStars : true }
    	}
    });

    You can also submit the form via ajax by using Malsup’s jQuery Form Plugin along with the jQuery validate code provided above.

    $('.rr_review_form').validate({
    	rules : {
    		input_stars : { selectStars : true }
    	},
    	submitHandler : function(form) {
    		// prepare the form for ajax submission
    		$(form).ajaxForm({
    			success : function() {},
    		});
    
    		// submit the form via ajax
    		$(form).ajaxSubmit();
    
    		// do your post submission tasks here, like hiding the form and displaying a success message.
    		// [NOTE: this really should be in "success" callback parameter, but for some reason that won't fire.]
    
    		// prevent the default submit
    		return false;
    	}
    });
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Ajax in form option?’ is closed to new replies.