CodeIgniter Forums
Error: The URI you submitted has disallowed characters - 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: Error: The URI you submitted has disallowed characters (/showthread.php?tid=49600)



Error: The URI you submitted has disallowed characters - El Forum - 02-26-2012

[eluser]Krystian[/eluser]
Hi,

I've coded sending messege to mail address from website using post in jQuery.

So, I`ve got a form and js like this:

Code:
var fc_name = $('#fc_name').val();
     var fc_company = $('#fc_company').val();
     var fc_phone = $('#fc_phone').val();
     var fc_email = $('#fc_email').val();
     var fc_text = $('#fc_text').val();
     //alert("Zapytanie od: " + fc_name); // for debug
    
     $.post
     (
    
      "<?php echo base_url(); ?>main/send_message",
      
      {
       // post_name:variable_value
      
       fc_name:fc_name,
       fc_text:fc_text
      },
      
      // re show the horizontal menu preview
      function(response){
      
       $('#message_result_box').val("Message has been sended :)");
      
      
      }
    
     )

and the controller method to which I`m sending post from js

Code:
function send_message()
{
  $this->load->library('email');

  $this->email->to('[email protected]');
  $this->email->from('[email protected]');
  $this->email->subject('Here is your info ' . $_POST['fc_name']);
  $this->email->message('This is the text message from website ' . $_POST['fc_text']);
  $this->email->send();
  
}

and in fire bug I`m getting
The URI you submitted has disallowed characters.

I`m using the newest ver of CI

p.s. when I run the controller method from url it sending mail without post vars of course.




Error: The URI you submitted has disallowed characters - El Forum - 02-26-2012

[eluser]CroNiX[/eluser]
Is your javascript you listed above in it's own file or is it a part of a php template? If it's a standalone js file, it won't be able to process your php you have in there for the base_url() and sending it as literal text. What URL does firebug say it's being sent to?


Error: The URI you submitted has disallowed characters - El Forum - 02-26-2012

[eluser]Krystian[/eluser]
js code is in separate js file

firebug


POST <?php echo base_url(); ?>main/sendmessage
400 Bad Request
943ms



Error: The URI you submitted has disallowed characters - El Forum - 02-26-2012

[eluser]CroNiX[/eluser]
Well, as I said, php doesn't get parsed in js files as evidenced by what you just posted (it's not interpreting the php, its posting it literally).

Easiest thing to do is create a js variable in the head of your php template which all of your javascript files can then use.

Code:
var base_url = "<?php echo base_url(); ?>";

Then in your javascript files, just base_url + 'controller/method/etc' to create the urls.



Error: The URI you submitted has disallowed characters - El Forum - 02-26-2012

[eluser]Krystian[/eluser]
Thanks Cronix!
or maybe create jQuery function which takes parameter. This parameter would be CI base url.

again thanks