PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 29, 2022

[FIXED] Codeigniter is not decoding email address

 January 29, 2022     codeigniter, php, urldecode     No comments   

Issue

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 ?


Solution

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.



Answered By - Alex
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing