2

I'm getting this error from CodeIgniter:

"The URI you submitted has disallowed characters. ..."

On this JSON string:

{"from":"feedback@myapp.com","to":"support@myapp.com","cc":"myadmin@ myapp.com, myfellowadmin@myapp.com","subject":"FROM APP: User Feedback","message":"FROM USER: testy.testerson@testme.com:\nHere's a test comment"}

When I try to encode it using:

URLreadyJSON = encodeURIComponent(JSON.stringify(JsonObj));

(JsonObj being the JSON string mentioned above.)

URLreadyJSON resolves to:

https://127.0.0.1/Xhr/email/%7B%22from%22%3A%22feedback%40myapp.com%22%2C%22to%22%3A%22support%40myapp.com%22%2C%22cc%22%3A%22myadmin%40myapp.com%2C%20myfellowadmin%40myapp.com%22%2C%22subject%22%3A%22FROM%20APP%3A%20User%20Feedback%22%2C%22message%22%3A%22FROM%20USER%3A%20testy.testerson%40testme.com%3A%5CnHere's%20a%20test%20comment%22%7D

The relevant code:

function sendFeedback() {
    JsonObj = { 
        'from': 'feedback@myapp.com',
        'to': 'support@myapp.com',
        'cc': 'myadmin@myapp.com, myfellowadmin@myapp.com',
        'subject': 'FROM APP: User Feedback',
        'message': 'FROM USER: ' + $('#feedback_email').val() + ":\n" + $('#feedback_message').val()
    }

    URLreadyJSON = encodeURIComponent(JSON.stringify(JsonObj));

    $.ajax({
        url: "/Xhr/email/" + URLreadyJSON,
        type: 'POST',
        dataType: 'json',
        success: function(data) {
            $('#feedback_feedback').text(data.message);
            if(!data.error) {
                $("#feedback_popup").popup("open");   // Open confirm popup
                $('#feedback_message').text('');      // Clear original message input
                $('#feedback_email').text('');        // Clear sender email
                setTimeout(function() { $("#feedback_popup").popup("close") }, 2500);
            }
        },
        fail: function(data) {
            console.log("FAIL");
            console.log(data);
        }
    });
}

and finally, in my CodeIgniter config file, I have the permitted_uri_chars set to:

$config['permitted_uri_chars'] = 'a-z 0-9~%.,":_?&=;}{@-';

I've gone over all the solutions I could find to this error (and there were a few) and incorporated the suggestions with no success. I must be missing something and am hoping someone can see what that something is.

KCL
  • 138
  • 1
  • 12
  • See if http://stackoverflow.com/questions/16271902/codeigniter-uri-disallowed-characters?rq=1 solves your problem – Gordon Nov 15 '15 at 10:36
  • Did you try using the following? $config['permitted_uri_chars'] = ''; //Allow all characters – Sultan Nov 27 '15 at 08:20

2 Answers2

3

Try to change :-

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\=';

TO

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\=+';
Sanjay Kumar
  • 424
  • 5
  • 15
1
function sendFeedback() {
JsonObj = { 
    'from': 'feedback@myapp.com',
    'to': 'support@myapp.com',
    'cc': 'myadmin@myapp.com, myfellowadmin@myapp.com',
    'subject': 'FROM APP: User Feedback',
    'message': 'FROM USER: ' + $('#feedback_email').val() + ":\n" + $('#feedback_message').val()
}

$.ajax({
    url: "/Xhr/email/",
    type: 'POST',
    dataType: 'json',
    data : JsonObj, // add this
    success: function(data) {
        $('#feedback_feedback').text(data.message);
        if(!data.error) {
            $("#feedback_popup").popup("open");   // Open confirm popup
            $('#feedback_message').text('');      // Clear original message input
            $('#feedback_email').text('');        // Clear sender email
            setTimeout(function() { $("#feedback_popup").popup("close") }, 2500);
        }
    },
    fail: function(data) {
        console.log("FAIL");
        console.log(data);
    }
});

}

server side:

$from: $this->input->post('from',true);
$to: $this->input->post('to',true);
$cc: $this->input->post('cc',true);
$subject: $this->input->post('subject',true);
$message: $this->input->post('message',true);
AldoZumaran
  • 547
  • 5
  • 23