Sending a POST request from an iframe, alerting the parent window href


Staff member
I'm building a Rails App, but the client also has a wordpress component.

I'd like to be able to allow users to sign up from one of the wordpress pages.

To do that, first I set the x-iframe header in Rails to ALLOWALL.

Now, the signup process works, but after the user makes the post request, I'd like the base window url to change to whatever the response is.

Currently, I'm trying to do something like this ->

  jQuery(function($) {
    var timesRun = 0;
    var original = "http://localhost:3000/mainsignup"

      timesRun += 1
      if (timesRun != 1) {
        window.location.href = "http://localhost:3000/signup?iframe_error=catch"

What this will do is that if the load event is called twice on this iframe(presumably because the user hits submit), I update the top window's location to go to the rails signup_path.

On Rails' ended, if the signup was successful, the signup_path redirects automatically to the user's profile. Otherwise, it renders the signup view, and inside it I have a generic error message, based on whether params[:iframe_error] exists.

This seems wrong though, and the user doesn't get specific error messages the first time. Is there a better way to do this?