Yaakov
Yaakov

Reputation: 184

PHP, JQuery Form submit redirect to another page

I have two forms in one page, registration and login. If a user try to enter a username into the "register_username" field, then on-blur, ajax check if this username already taken. It's all working properly. but I found out that if this ajax-call has been made, and then you click submit on the login form, it's redirect to the php-ajax page instead of the form-proccess php page.

I'm using Code-Ignitier as PHP framework, JQuery as javascript library and that's it. any additional information i'll try to deliver if i asked to do so. thank you very much.

Edit: //Javascript code:

$('#register_username').live('blur',function() {
 $.post('ajax/username_taken', {'register_username':$(this).val() },
 function(result) {
  if(result) {
   $('#register_username').addClass('error');
  }
  else {
   $('#register_username').removeClass('error');
  }
 });
}

//Php code

echo form_open('form/login',$form_attr);
echo ....
echo form_submit($submit_attr);
echo form_close();
echo form_open('form/register',$form_attr);
echo ....
echo form_submit($submit_attr);
echo form_close();

NOTE: This is all simplified, the forms are actually on different views, only register has a controller

Upvotes: 2

Views: 581

Answers (1)

user2742648
user2742648

Reputation:

I'm just blind-guessing since you didn't provide much info. It seems that your javascript overrides your submit button's click event so try adding this in your function(result) and see if anything changes:

$('submit_button_selector').unbind();

Ofcourse, change $('XXX') part with your button selector, generally it should be like $('#my_form).find(':submit')

Its really a blindshot and more info would help a lot.

Upvotes: 1

Related Questions