| 1 |
<?php |
| 2 |
|
| 3 |
namespace SpringDevs\Subscription\Traits; |
| 4 |
|
| 5 |
/** |
| 6 |
* Error handler trait |
| 7 |
*/ |
| 8 |
trait Form_Error { |
| 9 |
|
| 10 |
|
| 11 |
/** |
| 12 |
* Holds the errors |
| 13 |
* |
| 14 |
* @var array |
| 15 |
*/ |
| 16 |
public $errors = array(); |
| 17 |
|
| 18 |
/** |
| 19 |
* Check if the form has error |
| 20 |
* |
| 21 |
* @param string $key |
| 22 |
* |
| 23 |
* @return boolean |
| 24 |
*/ |
| 25 |
public function has_error( $key ) { |
| 26 |
return isset( $this->errors[ $key ] ) ? true : false; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Get the error by key |
| 31 |
* |
| 32 |
* @param key $key |
| 33 |
* |
| 34 |
* @return string | false |
| 35 |
*/ |
| 36 |
public function get_error( $key ) { |
| 37 |
if ( isset( $this->errors[ $key ] ) ) { |
| 38 |
return $this->errors[ $key ]; |
| 39 |
} |
| 40 |
|
| 41 |
return false; |
| 42 |
} |
| 43 |
} |
| 44 |
|