Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this in a php file from Contact Form 7, which I load into a modal window (FancyBox) and I would like to close it after the user will press the Submit button.

I was thinking of adding onSubmit="action" to the form but I don't know how or which one is the function I am supposed to use to close the modal window?

$form .= '<form action="' . esc_url_raw( $url ) . '" method="post"' . ' class="' . esc_attr( $class ) . '"' . $enctype . '>' . "\n";

Is this the right approach?

Also, if I can make it to click on a PayPal button right after that, it will be brilliant.

share|improve this question

closed as off-topic by kaiser Jul 28 at 14:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

    
Use esc_url instead of esc_url_raw, the raw version is for database storage and internal use inside of PHP. –  soulseekah Mar 13 '12 at 10:46

1 Answer 1

up vote 1 down vote accepted

Contact form 7 Lets you call a JavaScript function after the form has been submitted You will find the Additional Settings field at the bottom of the contact form management page and you need to use the hook named on_sent_ok something like this:

on_sent_ok: "$.fancybox.close();"
share|improve this answer
    
Thank you so much. This did the trick for me, and it was so simple. Is it possible to chain/trigger a click on a certain link/button I have on the page after the modal window is closed? –  C D Mar 13 '12 at 12:16
    
yeah you can create a JS function that will do what ever you want. –  Bainternet Mar 13 '12 at 13:08
    
I was looking so long for this, in case anyone else needs the same thing, there you go: on_sent_ok: "$.fancybox.close(); document.getElementById('paynow').click();" where paynow is the id of the submit button. –  C D Mar 13 '12 at 13:21
    
But the problem with this line is that one is jQuery and the other JavaScript and I think that's why the modal gets closed, then a new tab is opened, even if the user doesn't fill in the required fields. How would I write them both in jQuery or JavaScript? –  C D Mar 15 '12 at 16:08
    
@CristianDemetriad I just used on_sent_ok: "jQuery.fancybox.close();" and it worked changing $ to jQuery –  Anagio Jul 9 '12 at 17:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.