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

admin

Administrator
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 ->

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

    $('#sign-up-iframe').load(function(e){
      timesRun += 1
      if (timesRun != 1) {
        $(e.currentTarget).addClass('hidden')
        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?