GUMP::is_valid PHP Method

is_valid() public static method

Shorthand method for inline validation.
public static is_valid ( array $data, array $validators ) : mixed
$data array The data to be validated
$validators array The GUMP validators
return mixed True(boolean) or the array of error messages
    public static function is_valid(array $data, array $validators)
    {
        $gump = self::get_instance();
        $gump->validation_rules($validators);
        if ($gump->run($data) === false) {
            return $gump->get_readable_errors(false);
        } else {
            return true;
        }
    }

Usage Example

 public function delete()
 {
     $options = WebApp::post('options') === NULL ? array() : strgetcsv(WebApp::post('options'));
     if (count($options) == 0) {
         return new ActionResult($this, '/admin/core/option_view', 0, 'No option(s) were selected!', B_T_FAIL);
     }
     foreach ($options as $option) {
         $validated = GUMP::is_valid(array('opt' => $option), array('opt' => 'integer'));
         if ($validated !== true) {
             return new ActionResult($this, '/admin/core/option_view', 0, 'No option(s) were selected!', B_T_FAIL);
         }
     }
     $delete = $this->mySQL_w->prepare("DELETE FROM `core_options` WHERE `id`=?");
     $affected_rows = 0;
     foreach ($options as $id) {
         $delete->bind_param('i', $id);
         $delete->execute();
         $delete->store_result();
         $affected_rows += $delete->affected_rows;
     }
     if ($affected_rows == count($options)) {
         $this->parent->parent->logEvent($this::name_space, 'Deleted options: ' . csvgetstr($options));
         return new ActionResult($this, '/admin/core/option_view', 1, 'Successfully deleted selected option(s)!', B_T_SUCCESS);
     } else {
         $this->parent->parent->logEvent($this::name_space, 'Deleted some options: ' . csvgetstr($options));
         return new ActionResult($this, '/admin/core/option_view', 1, 'Successfully deleted ' . $affected_rows . '/' . count($options) . ' selected option(s)!<br /><small>Possible cause: <code>Unknown</code></small>', B_T_WARNING);
     }
 }
All Usage Examples Of GUMP::is_valid