tags:

views:

17

answers:

1

I have a form in Wordpress. When it is submitted, the page redirects to another page. But I want the page to stay the same, and for a modal to appear instead of a page redirect.

The following code is from the functions.php file that handles the form submission.

I'm not sure if this where I would introduce a modal. But this is where the redirect is triggered.

function group_buying_subscription()
{

 if( isset( $_POST['set-group-buying-subscription'] ) && !isset( $_POST['email_address'] ) ) {
  setcookie( 'your-selected-location', $_POST['deal_location'], time( ) + 24 * 60 * 60 * 30, '/' );
  wp_redirect( get_term_link( $_POST['deal_location'], 'deals') );
  exit();
 }
}

Let me know if you need anything else.

Thanks!

A: 

What you would need to do is first stop the form from submitting, and instead have the page be submitted through ajax (onsubmit, then return false) with the request going to wherever that function would handle it. Then override the wp_redirect and instead have it display content that you would grab through ajax and display into the modal box.

Obviously this is very general, and there are an almost infinite number of ways to implement this. I believe this would be the most straightfoward and simple solution.

theAlexPoon