• Resolved John

    (@dsl225)


    Hi folks,

    I’m working on a simple membership subscription form that collects basic user’s data at first page and then, when clicking on “subscribe” button has to generate, and display at a new page, an incremental membership number with some main data collected at previous page, like first and last name – and at the same time sends the same to the user’s email.

    Example:
    Page 1 will have the usual contact form fields with a subscription button
    Page 2 will display the name of the subscriber, plus a generated unique incremental membership number

    This second page doesn’t have any input fields, it’s only a sort of confirmation page that simply adds a unique calculated field.

    Confirmation email will hold all inputs by subscriber, plus his membership number (generated by the form).

    Would it be correct making the submission button conditional that reacts “when clicked” and generates a calculated field with incremental values at a new page (and sends the confirmation email), or is there a simpler solution?

    Thanks!

Viewing 15 replies - 1 through 15 (of 18 total)
  • Thread Starter John

    (@dsl225)

    PS: an alternative would be, if simpler, to automatically generate this membership unique number in a non editable field at first page and then having the second page simply display all fields as confirmation.

    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hello @dsl225,

    When you said, page 2 would display all the information, do you mean to say that user would be redirected to some other page or would that be post submission on the same page?

    Also, just to stay on the same page, you are working on the forminator user registration forms, right?

    Thank you,
    Prathamesh Palve

    Thread Starter John

    (@dsl225)

    Thanks Prathamesh,

    The initial idea is having the user being redirected at some other NEW page that displays his inputs of previous submission page and adds this membership number. In fact, that new page would display the same data he will receive by confirmation email + the membership incremental number that, in fact, can be the same as the {submission_id} in the email.

    But if it is simpler to have all user data at same page as the submission it can also be done but I don’t see how to generate this incremental ID in there.

    That ID membership number can be generated at any stage as it should be “read only” and will not require the user’s input.

    It is also important that this {submission_id} displays as column when exporting the submissions in CSV so that we can sort columns by that number.

    I’m working on a blank form for the moment but I can switch to your user registration template without problem if needed.

    Thanks!

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @dsl225

    Thank you for the information.

    I’m afraid it wouldn’t be possible using the default fields and would require some workarounds.

    Are you using a regular form only to collect the data or the registration form?

    Best Regards
    Patrick Freitas

    Thread Starter John

    (@dsl225)

    Hi Patrick,

    Thanks for your feedback!
    I’m currently testing with the regular form but I can switch to the registration form if needed without problem. And ready to use any needed workarounds!

    Please note that this is not for a website user registration!
    It’s a registration form for a free club membership.

    Thread Starter John

    (@dsl225)

    PS: I’m already using the Submission Behavior > After Submission > Redirect user to a URL and that works fine with existing fields of initial registration form.

    The only problem there is that I can’t figure out how to output this {submission_id} field at this second URL – which outputs fine in confirmation emails though.

    Thread Starter John

    (@dsl225)

    PS2: I see at this support ticket there is snippet for adding the Submission ID to the Google Sheet output and this is something I’m also going to do.

    Wondering whether there is something equivalent for doing the same at redirection URL that holds the second form with confirmation details.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @dsl225

    The solution for this other ticket is a bit different thing as it relates to Google Sheets integration and that’s executed at the different point of code execution. There’s not even a submission (entry) ID existing there.

    But I think I found a different one for you that seems to do the trick nicely. You’d want to use this code (you can add it to the site as MU plugin) with a small change.

    https://gist.github.com/wpmudev-sls/619d8140953daac80094abadad0ef66f

    The change would be:

    – in this line set your form ID (the form that is making the redirect, not the one you redirecting to)

    private $form_id = 2812;//enter form_id here

    – comment out or remove this line

    private $redirect_url = 'https://wp.local/inc/account/';//enter your redirect url here, it must be matches with the link you added on the form

    – and replace this

    public function add_entry_id_to_redirect_url( $content ){
      if( $this->entry_id && $this->redirect_url === $content ){
    		$content = add_query_arg('entry_id', $this->entry_id, $content);
    	}
    	return $content;
    }

    with this

    public function add_entry_id_to_redirect_url( $content ){
    $content = add_query_arg('entry_id', $this->entry_id, $content);
    return $content;
    }

    I’ve tested it on my end and it seems to be working fine. You’ll still need to add your fields to your redirect URL for examle like

    https://mysite.com/?name={name=1}

    but the submission ID (form entry ID) will be automatically appended to redirect URL.

    Best regards,
    Adam

    Thread Starter John

    (@dsl225)

    Hi Adam @wpmudev-support8 and many thanks for this, really appreciate.

    Indeed, it works great!
    The only thing is, if other readers follow this, that you have to add the string entry_id in the pre-populate section of the field you want to hold this ID.

    For what is worth, the confirmation string on top of submission form that is generated after successful submission get this at the end:
    Thank you for contacting us.?entry_id=45
    Not a problem for me as the new confirmation page opens immediately, but this is how I found out I had to add entry_id at destination field.

    Also, caution with the example you provided above ( https://mysite.com/?name={name=1} ) as I found out yesterday there is a bug with precisely this string.

    If you don’t mind, I would have 2 subsequent questions:

    – I initially tested this snippet for creating incremental values with an initial value of “1500” but I was getting mixed results as you can read at this ticket I also posted yesterday.

    I now de-activated this snippet and wondering whether we could add an initial value to this code here in order to get a custom value for the entry_id. For instance “1500”+”entry_id” or something similar?

    – Google Sheets: I have enabled this snippet in order to output the {submission_id} to Google Sheets. I cannot really test this at this point because I’m developing this website at a temporary URL but do you think both snippets (this one you just provided and the one for Google Sheets) can co-exist? Or should we somehow mix the code from the Google snippet to this one?

    Hope that makes some sense…

    Thread Starter John

    (@dsl225)

    UPDATE: I just found out that when this snippet is enabled it somehow blocks confirmation emails to be sent out! Submissions are correctly generated though under Forminator’s dashboard.

    I made several test and also traced outgoing messages by SMTP and it is very clear: no outgoing confirmation messages are being sent out. When I disable this snippet, outgoing messages are working again.

    There seems to be a conflict somewhere here…

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @dsl225,

    I now de-activated this snippet and wondering whether we could add an initial value to this code here in order to get a custom value for the entry_id. For instance “1500”+”entry_id” or something similar?

    I checked further with our developer to see if there is any workaround that could be looked into. The entry_id is taken directly from DB and has autoincrements. The easiest workaround would be set the Auto Increment as stated in here:
    https://www.ads-software.com/support/topic/can-we-set-a-start-number-for-the-submission_id-entry_id/#post-13568660

    Could you please check whether that would help in your use case? Please do make sure you test the workaround is a staging website before applying in live.

    – Google Sheets: I have enabled this snippet in order to output the {submission_id} to Google Sheets. I cannot really test this at this point because I’m developing this website at a temporary URL but do you think both snippets (this one you just provided and the one for Google Sheets) can co-exist? Or should we somehow mix the code from the Google snippet to this one?

    It shouldn’t be causing an issue in general with the above-mentioned workaround. However, please do note that we cannot fully state how it would work in every use case. Its something you’ll have to test on your side and see how it goes.

    I made several test and also traced outgoing messages by SMTP and it is very clear: no outgoing confirmation messages are being sent out. When I disable this snippet, outgoing messages are working again.

    I gave a quick test and could notice emails do get generated from the plugin side. Could you please double check via a plugin like Email Logs and see whether the emails are getting sent from the website side or not:
    https://www.ads-software.com/plugins/email-log/

    Please do let us know how that goes.

    Kind Regards,
    Nithin

    Thread Starter John

    (@dsl225)

    Hi Nithin @wpmudevsupport11 and many thanks for your feedback and time!

    I didn’t yet test the Auto Increment but this solution sounds to be the simplest and most effective indeed. Will give it a try later.

    Also noted your comments about Google Sheets and that’s good to know, thanks.

    Unfortunately, I still don’t manage to get those emails sent out.
    I strictly followed your instructions, and tested the code both in /mu-plugins/ and also as a snippet: with either of these methods nothing shows up in email logs, but when I remove this code emails are sent out again.

    The ID number generated by the form well outputs at redirected page but no emails are sent out. The only other difference I notice with code enabled is that the redirection page opens in new tab instead of same one, as it happens without that code enabled.

    I don’t see any potential plugin conflict at this point as I’m just starting with this site and there are only a few installed.

    The only thing I can imagine of would be that I edited the code wrong, although the form’s ID is really correct.

    Just to be sure, can you please double check it? Here is the code I used:

    <?php
    /**
     * Plugin Name: [Forminator] - Add entry id to redirect url
     * Description: [Forminator] - Add entry id to redirect url
     * Author: Thobk @ WPMUDEV
     * Author URI: https://premium.wpmudev.org
     * License: GPLv2 or later
     */
    if ( ! defined( 'ABSPATH' ) ) { exit; } elseif ( defined( 'WP_CLI' ) && WP_CLI ) { return; }
    
    add_action( 'plugins_loaded', 'wpmudev_forminator_add_entry_id_to_redirect_url_func', 100 );
    
    function wpmudev_forminator_add_entry_id_to_redirect_url_func() {
    	if ( defined('FORMINATOR_PRO') && class_exists( 'Forminator' ) ) {
    		class WPMUDEV_Forminator_Add_Entry_ID_To_Redirect_URL{
    			private $form_id = 18693;//enter form_id here
    			private $entry_id;
    
    			public function __construct(){
    				add_action( 'forminator_custom_form_submit_before_set_fields', array( $this, 'retrive_entry_id' ), 10, 2 );
    				add_filter( 'forminator_replace_form_data', array( $this, 'add_entry_id_to_redirect_url') );
    			}
    
    			public function retrive_entry_id( $entry, $form_id ){
    				if( $this->form_id == $form_id ){
    					$this->entry_id = $entry->entry_id;
    				}
    			}
    
    			public function add_entry_id_to_redirect_url( $content ){
    				$content = add_query_arg('entry_id', $this->entry_id, $content);
    				return $content;
    				}
    
    		}
    
    		$run = new WPMUDEV_Forminator_Add_Entry_ID_To_Redirect_URL;
    	}
    }

    Otherwise, I can also send you by email an admin access to the site for you to check if this something you can do.

    Thanks again!

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @dsl225

    I don’t see any potential plugin conflict at this point as I’m just starting with this site and there are only a few installed.

    I admit I’m a bit stuck with this too. There’s nothing in this code that’s supposed to stop e-mails form being send. I understand that there’s just few plugins on site but, just to make absolutely sure, could you try disabling them all, keeping only Forminator with this additional code and Twenty Twenty theme active and see if that changes anythign?

    Also, if there’s any other code related to Forminator (any other “customization” code) could you try without it too – so just Twenty Twenty theme, Forminator and this specific code?

    I understand that it’s probably not an issue but I’d just like to make absolutely sure about it and rule any possible conflicts out.

    Best regards,
    Adam

    Thread Starter John

    (@dsl225)

    Hi Adam @wpmudev-support8 and thanks for your feedback!

    I just did all that and, unfortunately, still not working…

    In fact I cloned the site at another location at same host so I was able to delete all plugins and replace the theme with twenty-twenty as you suggested.

    I added the code at /mu-plugins/ and I see it works because the ID is displaying at confirmation page, but still no emails. When I remove this code, emails work again. The same goes with the other issue I have here with that hook. Still no way to make this work either. For current test I didn’t add the above hook though, tests have been done separately.

    So, in this test installation, I have the code active in the /mu-plugin/ and only Forminator and Email Log active, plus the Twenty-Twenty.

    May I send you the link by email please?

    Thanks!

    Thread Starter John

    (@dsl225)

    UPDATE: I found out what’s happening!

    The registration form “redirects the user” to a confirmation page with the option to “redirect on the same tab”.
    This confirmation page has, by default, a SUBMIT button at bottom that I was hiding with CSS because, in the basic version that runs without this code, there is nothing to submit as it is supposed just to display a confirmation of what the user has entered at previous page.

    When enabling this code, I noticed that this confirmation page opens in a new tab instead of “same tab” as defined in the redirection. So, apparently, the code is waiting for an action to be taken at this second page – which is quite annoying in fact. So I removed my CSS and made this submit button visible again and when clicking on it emails are indeed being sent out!

    So, now the problem is a bit different:
    – How to make this second submission not required as the user has already submitted his registration and he’s not expecting to resubmit anything more as this second page is supposed to summarize his registration?

    In summary: without this code, emails are fired after initial form submission. When this code is enabled, they are fired only when submitting again the second form.

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Generating an incremental number upon submission’ is closed to new replies.