Welcome Guest, Not a member yet? Register   Sign In
sanitize textarea input for database insertion - best practice
#4

Thx for the feedback. Below seems to work fairly well.

@InsiteFX.. I threw your code into my helper file. Thx.

So here is what I have:
Controller:
- Validate:
Code:
$this->form_validation->set_rules('f_text', 'Review Text', 'required|trim|callback_customAlphaTwo');
 - the callback
Code:
   public function customAlphaTwo($str)
   {
       if (!preg_match('/^[a-zA-Z0-9 .,\-\'\&\–\—\«\»\…\$\[\]\/\(\)\“\”\‘\’\!\;\:\é]*$/m', $str)) {
           return FALSE;
       } else {
           return TRUE;
       }
   }
- clean Text
Code:
$tCleanText = cleanText($this->input->post('f_text'));

- Save Data
Code:
$aDataToSave = array(
 'far_text' => $tCleanText,
 // more stuff
)
$tinsert = $this->admindata->savedata($aDataToSave);

Note: cleanText() is a helper

Model:
- Insert
Code:
   // Save Data
   public function savedata($tdata)
   {
       return $this->db->insert('db_table', $tdata);
   }
Reply


Messages In This Thread
RE: sanitize textarea input for database insertion - best practice - by dbrooke - 06-27-2019, 08:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB