Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

Override form target with jquery etc

Hi, am using a wordpress plugin User Meta Pro to show a login and register form - in a Fancybox iframe. So the problem is when the user clicks submit in either form it opens up the target url in the iframe...is it possible to override the default target for the form and set it to parent?

Below is code I have tried - this method worked in the past when I knew the form had no target defined by default. This time I am dealing with a plugin - the coders are not getting back to me on this - and I cannot find where the form code is generated so want to just override the target part - is it possible somehow? Is there a way to intercept the default action before it executes (I presume the problem)? Thanks.

$("#insert_user").click(function(){        // The button to submit form
$(".um_user_form").attr('target', '_parent');     // The form attribute
});
0
alexmaestro100
Asked:
alexmaestro100
  • 8
  • 6
1 Solution
 
leakim971PluritechnicianCommented:
no need to wait for the click, put the target on DOM ready :

$(document).ready(function() {
       var form = $(".um_user_form");
       if(form.length==0) alert("FORM NOT FOUND!!!"); // REMOVE THIS IF IT WORK
       form.attr('target', '_parent'); // THAT WORK ONLY IF PARENT AND CHILDREN ARE IN THE SAME DOMAIN
});

Open in new window


if that don't work please provide a link to your wordpress site : http://goo.gl
0
 
alexmaestro100Author Commented:
Sorry that's basically what I've already tried. I am working locally so cannot give website link, thanks anyway.
0
 
leakim971PluritechnicianCommented:
A local wordpress site? OK....
I added an alert what it say?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
alexmaestro100Author Commented:
Your alert comes up - and also I noticed the form target is loaded as parent in the browser with the rest of your code. But it does not target parent when submitting form.

In the form code there is this line: onsubmit="umInsertUser(this); return false;

which I presume may be the problem, but don't know how to override it's target value! Thanks for suggestions.
0
 
leakim971PluritechnicianCommented:
if the alert comes up that mean you did not have the form when the script run...
0
 
alexmaestro100Author Commented:
OK how can I fix this? Thanks.
0
 
leakim971PluritechnicianCommented:
please confirm :
- you put the code to the page in the iframe not in the parent
- both page are on the same domain
0
 
alexmaestro100Author Commented:
Both yes - and I can see the code for the form target is affected, it just doesn't work when submitted. The alert does not come up (unless I take the 'if' out).

I am trying a workaround by putting "parent.$.fancybox.close()" on the submit button and redirecting manually - this works but ruins the form validation - is there a way with jquery to only do the code if the form is sent (filled out correctly)? All the validation is in place, just needs something on the button code.

I would obviously prefer your solution! Thanks.
0
 
leakim971PluritechnicianCommented:
In the form code there is this line: onsubmit="umInsertUser(this); return false;

try this :
$(document).ready(function() {

$("form:eq(0)").removeAttr("onsubmit").submit(function(evt) {
alert("test ok");
      evt.preventDefault();
      $(".um_user_form").attr('target', '_parent');;
      umInsertUser(this);
});

})

Open in new window

0
 
alexmaestro100Author Commented:
The alert came up OK but still no target parent!!!! Thanks for the effort!
0
 
leakim971PluritechnicianCommented:
ok, so I can help you more without seeing your page, so if you're gonna to put this wordpress site online, let me know or just wait help of someone else.
0
 
alexmaestro100Author Commented:
Thanks anyway.
0
 
alexmaestro100Author Commented:
It's me again! I just loaded the content into fancybox with a div, no need for iframe! Thanks for help anyway.
0
 
alexmaestro100Author Commented:
I solved it myself.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now