CodeIgniter Forums
Codeigniter is not decoding email address - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Codeigniter is not decoding email address (/showthread.php?tid=73872)



Codeigniter is not decoding email address - Abdulmanan0315 - 06-15-2019

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 ?


RE: Codeigniter is not decoding email address - Abdulmanan0315 - 06-20-2019

According to CI3 documentation we can easily set a valid php function in the form validation third parameter. in my case i d need to use
$this->form_validation->set_rules('email', 'Email', 'trim|**urldecode**|required|valid_email|is_unique[users.email]');


RE: Codeigniter is not decoding email address - InsiteFX - 07-02-2019

Are you json_decode(array) in your controller?