Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Update system/libraries/Form_validation.php #1824

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+7 −1
Split
@@ -980,7 +980,7 @@ public function matches($str, $field)
* Is Unique
*
* Check if the input value doesn't already exist
- * in the specified database field.
+ * in the specified database field with option ignore edited record.
*
* @param string
* @param string field
@@ -991,6 +991,12 @@ public function is_unique($str, $field)
list($table, $field) = explode('.', $field);
if (isset($this->CI->db))
{
+ if (strpos($field, ','))
+ {
+ list($field, $id) = explode(',', $field);
+ $primary = $this->CI->db->query("SHOW KEYS FROM $table WHERE Key_name = 'PRIMARY'")->row();
+ $this->CI->db->where($primary->Column_name.' <>', $id);
+ }
$query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
return $query->num_rows() === 0;
}