Help escaping at sign (@) from ajax to php - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Help escaping at sign (@) from ajax to php (/showthread.php?tid=23378) |
Help escaping at sign (@) from ajax to php - El Forum - 10-08-2009 [eluser]digitaleye[/eluser] Hi I seem to be having a problem with some code. I have a check for an email address, which checks validity whilst typing, plus checks a database for an already registered email. The code i have is as follows : Javascript in the view ... Code: $('#email').keyup(function() { Controller info ... Code: function email_callback() The problem i'm having seems to be with the at sign (@), as when i echo the output, nothing shows. I have tried escaping the email input, then decoding the php, but everything I try doesn't output the correct info. Any help appreciated. Thanks Help escaping at sign (@) from ajax to php - El Forum - 10-08-2009 [eluser]Scal[/eluser] Hi; are you meaning the issue is in the reg exp evaluation? If so, why not use the valid_email() CI Email Helper function? If not and talking about the $mail variable not being set like if it was not sent with the ajax call, did you try changing the type to 'POST'? Help escaping at sign (@) from ajax to php - El Forum - 10-09-2009 [eluser]digitaleye[/eluser] Hi The content of the email field does seem to be being sent via post; I am checking this by echoing the input. However, as soon as i type the @ nothing is sent from this character onwards. For example I enter [email protected] into the email field The characters echo'd are test then nothing else, as though the @ is stopping the function. Thanks Help escaping at sign (@) from ajax to php - El Forum - 10-09-2009 [eluser]rogierb[/eluser] Can you post a print_r on $_POST? Help escaping at sign (@) from ajax to php - El Forum - 10-09-2009 [eluser]digitaleye[/eluser] Hi When I enter [email protected] in the email field I get Code: Array ( [email] => test ) Thanks Help escaping at sign (@) from ajax to php - El Forum - 10-09-2009 [eluser]rogierb[/eluser] can you change the ajax call Code: data: "email="+escape(email), to Code: data: {email:$("#email").val(),email2:'[email protected]', email3:escape($("#email").val())}, and do a print_r on $_POST again? Help escaping at sign (@) from ajax to php - El Forum - 10-09-2009 [eluser]digitaleye[/eluser] Hi Output of $_POST Code: Array ( [email] => test [email2] => [email protected] [email3] => test ) Thanks Help escaping at sign (@) from ajax to php - El Forum - 10-09-2009 [eluser]Chad Fulton[/eluser] Your problem is that in your AJAX request, you're setting the URL to be 'email_callback/'+$(this).val(). Now recall that in the context of the $('#email').keyup event, $(this) is bound to the #email element, which is your e-mail address form input. So, you're pointing the URL of the AJAX request to, for example, 'email_callback/[email protected]'. The problem here is that CodeIgniter doesn't allow the @ symbol in URI's, so whenever you get to the @ symbol, CodeIgniter prevents the script from running your email_callback() function. Fortunately for you, you don't seem to be using that anyway, so you can just remove it, like so: Code: $('#email').keyup(function() { Good luck! Help escaping at sign (@) from ajax to php - El Forum - 10-09-2009 [eluser]rogierb[/eluser] There are a couple of possibilities as far as I can see. 1: your $_POST gets scrubbed. Do you xss cleaning on by default(or something else? 2: $("#email").val(); does not contain an email address, try alert($("#email").val()) before the ajax call 3: $("#email").val() does not get posted properly, try something like email:"'"+$("#email").val()+"'" to see if that makes any difference Help escaping at sign (@) from ajax to php - El Forum - 10-09-2009 [eluser]digitaleye[/eluser] [quote author="Chad Fulton" date="1255100339"] So, you're pointing the URL of the AJAX request to, for example, 'email_callback/[email protected]'. The problem here is that CodeIgniter doesn't allow the @ symbol in URI's, so whenever you get to the @ symbol, CodeIgniter prevents the script from running your email_callback() function. Fortunately for you, you don't seem to be using that anyway, so you can just remove it, like so: Code: $('#email').keyup(function() { Good luck![/quote] This has worked great. Thanks everyone for your help, very much appreciated. |