• Resolved Jon Schroeder

    (@jonschr)


    I’m really interested in using this plugin; love the idea and the flexibility.

    I’d like to be able to redirect to a URL and also pass some either GET or POST parameters from the form. It doesn’t appear possible to do that at present with this plugin, but I wanted to check and see if it might be!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hey Jon,

    Glad you like the idea! Hope we can make this work for you.

    Right now there should be a “Redirect to URL” setting when you open up the “Settings” tab on the page where you edit your form.

    You can enter an absolute URL in there, but right now this field does not accept field variables to reference field data (like the email fields do), but I do see how this can be super useful. We’ll add that in so that you can do stuff like this:

    
    https://site.com/thank-you?email=[EMAIL]
    

    If you’re in a hurry with this then I would suggest using the following action hook in PHP instead.

    
    add_action( 'hf_form_success', function( $submission, $form ) {
        // redirect to URL with parameters added to it
        $redirect_url = add_query_arg ( array( 'email' => $_POST['EMAIL'] ), 'https://site.com/thank-you' );
        wp_redirect( $redirect_url ); 
        exit;
    }, 10, 2 );
    

    Hope that helps! Let me know if I can help with anything else.

    Hi Danny!

    I’m playing around with the hf_formm_success hook and using the action you gave as an example, but nothing seems to happen; the form gets submitted, but the console gives an error:

    HTML Forms: failed to parse AJAX response.
    
    Error: "SyntaxError: Unexpected token < in JSON at position 0"

    I tried to add another action, which gives the same error, but then with ‘Unexpected token A’.
    No idea where the ‘A’ is coming from though :-S

    What I’m actually trying to accomplish is that after submission, the submitted values are saved in a XML file (using SimpleXML) that then needs to be send as an attachment to a defined mail address (any tips are much appreciated :-)).

    Last but not least: I really love the concept of this plugin! Thx!

    Update: I just found out my added action to send an email with xml-file attached does work anyway. The mails were in my spam-box.

    Hey Tibor!

    Nice, glad to hear that part is working already and happy you’re digging the plugin so far!

    Most likely, the code part where you’re hooking into hf_form_success is throwing a fatal error which is breaking the AJAX response. Checking the actual response that happens when you submit the form using the “Network” tab in your Chrome developer tools should be helpful here in locating the actual error. Another option is to check your PHP error log.

    Thread Starter Jon Schroeder

    (@jonschr)

    So sorry that I missed the notification from your reply. Came looking today to see if you had. That’s awesome! I’ll definitely use that, and this seems simple enough (even if your shortcode-ish implementation isn’t yet finished).

    I’m using this because I have some relatively custom pricing I want to output, but there’s an abbreviated view and a “full” view to it, like this site: https://www.maidsinblack.com/

    Great work; I love the flexibility of this.

    Thread Starter Jon Schroeder

    (@jonschr)

    Oh, and a question on the example action you posted: it looks like it’s generic (e.g. fires whenever *any* form submits. Is there a version of that action that’s specific to the ID of a particular form?

    Hi Jon,

    Sorry, my turn to miss your “reply notification”. Ugh.

    The second parameter that is passed to the action hook contains the form object of the form that was submitted. This form contains properties that can be used to determine which form you want to act on.

    
    add_action( 'hf_form_success', function( $submission, $form ) {
        // only act on form with slug "my-contact-form"
        if( $form->slug !== 'my-contact-form' ) { 
            return; 
        }
    
        // redirect to URL with parameters added to it
        $redirect_url = add_query_arg ( array( 'email' => $_POST['EMAIL'] ), 'https://site.com/thank-you' );
        wp_redirect( $redirect_url ); 
        exit;
    }, 10, 2 );
    

    We’re probably going to add form specific action hooks though, but haven’t yet at this point.

    Does that help though?

    Hey Jon,

    Just wanted to let you know that in version 1.0.6 you can now do the following:

    
    add_action( 'hf_form_my-contact-form_success', function( $submission, $form ) {
        // redirect to URL with parameters added to it
        $redirect_url = add_query_arg ( array( 'email' => $_POST['EMAIL'] ), 'https://site.com/thank-you' );
        wp_redirect( $redirect_url ); 
        exit;
    }, 10, 2 );
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Redirect after submission’ is closed to new replies.