KCL
KCL

Reputation: 140

CodeIgniter throwing "The URI you submitted has disallowed characters..." and I can't see what's causing it

I'm getting this error from CodeIgniter:

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

On this JSON string:

{"from":"[email protected]","to":"[email protected]","cc":"myadmin@ myapp.com, [email protected]","subject":"FROM APP: User Feedback","message":"FROM USER: [email protected]:\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': '[email protected]',
        'to': '[email protected]',
        'cc': '[email protected], [email protected]',
        '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.

Upvotes: 2

Views: 1095

Answers (2)

Sanjay Kumar
Sanjay Kumar

Reputation: 424

Try to change :-

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

TO

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

Upvotes: 3

AldoZumaran
AldoZumaran

Reputation: 572

function sendFeedback() {
JsonObj = { 
    'from': '[email protected]',
    'to': '[email protected]',
    'cc': '[email protected], [email protected]',
    '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);

Upvotes: 1

Related Questions