Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class MY_Form_validation extends CI_Form_validation {
  4.  
  5. protected $CI;
  6.  
  7. public function __construct($rules = array())
  8. {
  9. parent::__construct($rules);
  10. $this->CI =& get_instance();
  11. }
  12.  
  13.  
  14. /**
  15. * is_unique_multiple
  16. * check multiple unique field at time
  17. * handy when checking if two or more column of some set of value
  18. * e.g if firstname="something" and username="something"
  19. * usage:
  20. is_unique_multiple[
  21. table_name,
  22. column_name1.column_name2.column_name3,
  23. post_filed_name1.post_field_name2.post_field_name3
  24. ]
  25.  
  26. *real example
  27. $this->form_validation->set_rules('fee_name', 'fee_name', "required|is_unique_multiple[arasoft_fee, fee_name.fee_term.fee_users, fee_name.term.fee_users ]");
  28. **/
  29. public function is_unique_multiple($str,$data)
  30. {
  31. $data = explode(",", $data);
  32. if(count($data)<2)
  33. return TRUE;
  34.  
  35. $table = @$data[0];
  36. $str = @$data[1];
  37. $str = explode(".", $str);
  38. $field = @$data[2];
  39. //var_dump($table,$str,$field);exit();
  40. $field = empty($field) ? $str : explode(".", $field);
  41. if(count($str) != count($field)){
  42. return TRUE;
  43. }
  44. $where = [];
  45.  
  46. foreach ($str as $key => $value) {
  47. # code...
  48. $q = $this->CI->input->post($field[$key]);
  49. $where[$value] = $q;
  50. }
  51.  
  52. $check = $this->CI->db->get_where($table, $where, 1);
  53.  
  54. if ($check->num_rows() > 0) {
  55.  
  56. $this->set_message('is_unique_multiple', 'This data exist already');
  57.  
  58. return FALSE;
  59. }
  60.  
  61. return TRUE;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement