dezio Posted May 15, 2013 Share Posted May 15, 2013 I am trying to edit phone number before it gets updated in db but I cannot figure out can I do that. I am using this code: function hook_filter_clients_data($vars) { $vars['phonenumber'] = preg_replace("/[^0-9]/", '', $vars['phonenumber']); return $vars; } add_hook("ClientEdit",1,"hook_filter_clients_data"); but it doesnt work. I also tried to change $vars to &$vars but still nothing... Is there any other way to do it? 0 Quote Link to comment Share on other sites More sharing options...
synik4l Posted May 16, 2013 Share Posted May 16, 2013 I am trying to edit phone number before it gets updated in db but I cannot figure out can I do that. I am using this code: function hook_filter_clients_data($vars) { $vars['phonenumber'] = preg_replace("/[^0-9]/", '', $vars['phonenumber']); return $vars; } add_hook("ClientEdit",1,"hook_filter_clients_data"); but it doesnt work. I also tried to change $vars to &$vars but still nothing... Is there any other way to do it? First off why are you doing this in this first place? It seems like your trying to sanitize it? Or something? Which you wouldnt need to do. Cus whmcs does that im sure. but in case you do need it for some reason: Your problem is you cant send data back into the $vars variable. returning $vars just sends vars back to the function that called the hook. and it will do nothing with it there. so to do this you need to use php mysql or mysqli. I recommend starting using mysql if u havent done any before. You'll have to update tblclients phone number column. based on the userid of the user being edited which you can find in $vars["params"] so its gonna look something like $userid = $vars["params"]["userid"]; then your gonna have to do UPDATE tblclients SET phonenumber=? WHERE userid=? the ? marks are the parameters. So you'll have to look up how to do that. mysqli and mysql do it differently. 0 Quote Link to comment Share on other sites More sharing options...
dezio Posted May 16, 2013 Author Share Posted May 16, 2013 Thanks for reply synik4l. I do it because Resell.biz module doesnt create phone number in a right format when registering new client in their API. So this is solution I tried and it works function hook_filter_clients_data($vars) { $phonenumber = preg_replace( array( "/[^0-9]/", "/^[0]{1}/" ), array( '', '' ), $vars['phonenumber']); $table = "tblclients"; $update = array( 'phonenumber' => $phonenumber ); $where = array( 'id' => $vars['userid'] ); update_query($table, $update, $where); } add_hook("ClientAdd",1,"hook_filter_clients_data"); add_hook("ClientEdit",1,"hook_filter_clients_data"); 0 Quote Link to comment Share on other sites More sharing options...
synik4l Posted May 16, 2013 Share Posted May 16, 2013 Thanks for reply synik4l. I do it because Resell.biz module doesnt create phone number in a right format when registering new client in their API. So this is solution I tried and it works function hook_filter_clients_data($vars) { $phonenumber = preg_replace( array( "/[^0-9]/", "/^[0]{1}/" ), array( '', '' ), $vars['phonenumber']); $table = "tblclients"; $update = array( 'phonenumber' => $phonenumber ); $where = array( 'id' => $vars['userid'] ); update_query($table, $update, $where); } add_hook("ClientAdd",1,"hook_filter_clients_data"); add_hook("ClientEdit",1,"hook_filter_clients_data"); Do they really do it wrong? Dang...looks like ill have to fix that too before we go live...Thanks for info. Glad to help 0 Quote Link to comment Share on other sites More sharing options...
dezio Posted May 16, 2013 Author Share Posted May 16, 2013 (edited) Depends in which format your customers enter their phone number.. Please note preg_replace function. I wanted to remove leading zero, so you must remove that part for your customers if you dont want leading zero from phone number to be removed. Edited May 16, 2013 by dezio 0 Quote Link to comment Share on other sites More sharing options...
synik4l Posted May 16, 2013 Share Posted May 16, 2013 ya i dont need a leading 0 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.