• Resolved tgilber007

    (@tgilber007)


    Hi, we need to limit form submission per user.
    Logged in user visited the form, he fills the form and and it was successfully submitted

    We want to restrict him from submitting that same form he’d be privileged to submit again.

    Can we archive that?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter tgilber007

    (@tgilber007)

    And How to give mycred plugin points after submitting a poll or quiz.

    Hello @tgilber007 !

    I hope you’re doing great today!

    Forminator doesn’t have an option for this built in yet, but if you’re using a form, you can use this snippet to limit the submissions to once per user:

    <?php
    
    add_filter(
    	'forminator_render_form_markup',
    	function( $html, $form_fields, $form_type, $form_settings, $form_design, $render_id ) {
    		if ( is_user_logged_in() ) {
    			global $wpdb;
    			$user_id_field_name = 'hidden-1';
    			$user_id            = get_current_user_id();
    			$message            = __( 'You can submit this form only once' );
    
    			$user_entries = $wpdb->get_var(
    				$wpdb->prepare(
    					"SELECT COUNT(e.entry_id) FROM {$wpdb->prefix}frmt_form_entry as e
    					INNER JOIN {$wpdb->prefix}frmt_form_entry_meta as m ON e.entry_id=m.entry_id
    					WHERE m.meta_key=%s AND m.meta_value=%d 
    					LIMIT 1",
    					$user_id_field_name,
    					$user_id
    				)
    			);
    
    			if ( ! empty( $user_entries ) || 0 < $user_entries ) {
    				return $message;
    			}
    		}
    
    		return $html;
    	},
    	10,
    	6
    );

    To install the script, please copy the code to a .php file and place it in wp-content/mu-plugins directory after adjusting.

    To adjust:

    Your form will need to have a Hidden field added with default value set to “User ID”. If the field is named hidden-1, no adjustments are needed.

    If the field has a different name, you’ll need to change the line:

    $user_id_field_name = 'hidden-1';

    To match the identifier of the field.

    Then the form will be checking if there’s already a submission for the same form from the current user and will prevent the form from being sent.

    Regarding the part about the myCred plugin – this will require custom coding depending on how that plugin accepts points. From the Forminator side you can use the Forminator API which has documentation available here: https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/

    This will certainly require custom coding to connect the two plugins together – very likely hiring a developer will be necessary in this case to review the myCred documentation as well.

    Best regards,
    Pawel

    Thread Starter tgilber007

    (@tgilber007)

    Thank you for reply
    the above code is work well with forms but how limit submission in polls and quiz how to achieve this

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @tgilber007

    For Poll, you can use the Forminator Poll setting https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#voting-limit

    You can use the WPMU DEV Branda plugin to replace the “You have already voted for this poll.” string https://wpmudev.com/docs/wpmu-dev-plugins/branda/#text-replacement or the Forminator PO / MO Files.

    For Quiz, are you collecting Leads on your Quiz?

    Best Regards
    Patrick Freitas

    Thread Starter tgilber007

    (@tgilber007)

    1.In Poll Voting Limit method how to I add the third option User Ip, Brower cookie, third One (User Id) #limit submission by user id

    2. In poll how to display a final custom messages to the users like in quiz->behaviour-> final message

    3. For Quiz, yes i collecting Leads on Quiz?

    • This reply was modified 2 years, 9 months ago by tgilber007.
    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @tgilber007

    3. For Quiz, yes i collecting Leads on Quiz?

    In this case, the same code shared in our initial reply will work, you just need to add the hidden field in Lead Form.

    1.In Poll Voting Limit method how to I add the third option User Ip, Brower cookie, third One (User Id) #limit submission by user id

    I am afraid it isn’t possible, the table structure is different for Poll, but I added this ticket as a feature request to our developers.

    2. In poll how to display a final custom messages to the users like in quiz->behaviour-> final message

    It is not possible but you can use this Script:

    jQuery('body').on('forminator:poll:submit:success', function( ajaxData, formData ){
    
    console.log('ok');
    
    });

    Make sure your Poll is submitted by Ajax https://monosnap.com/file/wMycscchIDSxIW1dLsNyrqVcBSbNUK

    It will trigger the event forminator:poll:submit:success which you can use to for example inject an HTML in your page.

    https://api.jquery.com/append/

    Best Regards
    Patrick Freitas

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @tgilber007 ,

    We haven’t heard from you for a while now, so it looks like you don’t have more questions for us.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

    Hi, we have a similar request and would be very grateful for help!

    We would also like to limit the submission of a form to one submission only.

    This should be done independently of a user ID, but based on the submission ID, which is already taken as pre-populate and added as the label “order number” in the new form. Once submitted no one else should be able to submit the same form.

    Thanks a lot!

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @thankssforhelp

    I hope you’re well today!

    As per this forum rules, it’s recommended to start separate tickets in such cases. I know that you have already done that and I’ve already responded to it so let’s continue there.

    Kind regards,
    Adam

    The script you have written is working well with 1 limit per user. Can you please prepare the same script for but the max user submission to 4.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @shahifits

    As per this forum guidelines, it’s require to open a separate ticket.

    I see you have already started a separate ticket and I’ve responded to you there:

    https://www.ads-software.com/support/topic/limit-user-submission-to-max-4-submits-per-id-not-ip/

    Kind regards,
    Adam

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Limit submission by user’ is closed to new replies.