简体   繁体   中英

Codeigniter is not decoding email address

I am sending my email address through a form which is submitted by ajax to controller and the data for the ajax is created by this function:

// Function "serializeToJson" - Serialize form data, merge new object and returns json object
function serializeToJson(element, newObj){
    // Serialize form and split into Json Object
    var data = element.serialize().split("&");
    var object = {};
    for(var key in data){
        object[data[key].split("=")[0]] = data[key].split("=")[1];
    }

    // Merge new json obj to existing json object
    const target = {};
    $.extend(target, newObj, object);

    // return the final json object
    return target;
}

and in my ajax

data : serializeToJson(SUform, {action:'process_signup'}),

The email which is being sent through the form is getting urlencoded ie

xxxxxxxxxx%40gmail.com

the %40 should be decoded to @ when i receive the data in my controller. In my controller i have set the following form validation rules for email:

$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]');

The error:

The Email field must contain a valid email address

What i want?

Is there any way by which i can urldecode the email in form validation ?

You can use:

trim|urldecode|valid_email

It should work as the docs say you can use any php function as a "rule" and it will apply.

You'll still have to urldecode it again for when you put it in the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM