Skip to content

Commit

Permalink
Fix checkPostFieldData function to extend the core Input method
Browse files Browse the repository at this point in the history
  • Loading branch information
brendo committed May 29, 2012
1 parent ac4a5ec commit 3d8cf91
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions fields/field.uniqueinput.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function allowDatasourceOutputGrouping(){
Utilities:
-------------------------------------------------------------------------*/

public function __isHandleUnique($handle, $self_entry_id=NULL){
public function isHandleUnique($handle, $self_entry_id=NULL){
return !(bool)Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_entries_data_" . $this->get('id') . "` WHERE `handle` = '$handle' ".(is_numeric($self_entry_id) ? " AND `entry_id` != $self_entry_id " : NULL) . "LIMIT 1");
}

Expand Down Expand Up @@ -72,19 +72,15 @@ public function commit(){
-------------------------------------------------------------------------*/

public function checkPostFieldData($data, &$message = null, $entry_id = null){
$handle = Lang::createHandle($data);
$status = parent::checkPostFieldData($data, $message, $entry_id);

if($this->get('required') == 'yes' && strlen($data) == 0){
$message = __('‘%s’ is a required field.', array($this->get('label')));
return self::__MISSING_FIELDS__;
if($status !== self::__OK__) {
return $status;
}

if(!$this->__applyValidationRules($data)){
$message = __('‘%s’ contains invalid data. Please check the contents.', array($this->get('label')));
return self::__INVALID_FIELDS__;
}
$handle = Lang::createHandle($data);

if($this->get('auto_unique') != 'yes' && !$this->__isHandleUnique($handle, $entry_id)){
if($this->get('auto_unique') != 'yes' && !$this->isHandleUnique($handle, $entry_id)){
$message = __('Value must be unique.');
return self::__INVALID_FIELDS__;
}
Expand All @@ -106,7 +102,7 @@ public function processRawFieldData($data, &$status, &$message=null, $simulate=f
$status = self::__OK__;
$handle = Lang::createHandle($data);

if($this->get('auto_unique') == 'yes' && !$this->__isHandleUnique($handle, $entry_id)){
if($this->get('auto_unique') == 'yes' && !$this->isHandleUnique($handle, $entry_id)){
$existing = NULL;

// First, check to see if the handle even needs to change
Expand Down

0 comments on commit 3d8cf91

Please sign in to comment.