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 i.e.
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.