By orgnsm on
Hello, I'm loading the user registration form into a container and then attaching a submit event that should post the form data but the only response I get is an empty registration form...
$("#add-user").click(function(){
$( "#container" ).load( $(this).attr("href")+" #user-register-form" );
return false;
});
$( "#container #user-register-form" ).live("submit",function(){
var values = $(this).serialize();
var target = "http://"+document.domain+$(this).attr("action");
$.ajax({
type: "POST",
url: target,
data: values,
success: function(re){
$("#container").html( $(re).find(".messages") );
$("#container").append( $(re).find("#user-register-form") );
}
});
return false;
});Note that I use this exact methodology to create/edit/delete nodes of various content types with no problems. Any ideas about this are greatly appreciated.
Comments
If I use a more Drupal
If I use a more Drupal-oriented approach, I have the same problem. Here is my HOOK_form_alter:
and my AJAX callback:
This works fine until I load the form into a page with this javascript:
At this point the AJAX submit function is lost and I have no idea why.
You almost have everything
You almost have everything correct. The problem is that you are generating your $settings, and then calling render() on the form, which then generates all the settings related to that form. But since you've already generated your $settings, these new settings are not included.
Call render() before generating your settings.
Contact me to contract me for D7 -> D10/11 migrations.
works now! I got the
works now! I got the $settings properly added to the rendered form. then had to edit my javascript some to make sure JQuery was executing the $settings...
additionally, a couple of libraries were needed:
thanks so much Jay, you set me on the right track and seem to have helped many people with AJAX in Drupal. cheers
now that this works, do you
That's really a different
That's really a different question, and I don't use #states much myself (I prefer to write my own), so I'd suggest starting a new thread on the matter.
Contact me to contract me for D7 -> D10/11 migrations.