Fixes in modelforms

This commit is contained in:
Antonio de la Rosa 2024-10-11 20:15:53 +02:00
parent a30676de2f
commit 3dcd035e4c
3 changed files with 28 additions and 5 deletions

View file

@ -30,6 +30,7 @@ class BaseForm {
public $field;
public $comment_form='';
public $code_error=0;
public $error=0;
public $txt_error='';
public $extra_param='';
public $parameters=[];

View file

@ -2,7 +2,7 @@
namespace PhangoApp\PhaForms\Forms;
use PhangoApp\PhaModels\Forms\BaseForm;
use PhangoApp\PhaForms\Forms\BaseForm;
/**
* Basic class for create forms

View file

@ -312,7 +312,7 @@ class ModelForm {
}
$form->error_flag=1;
$form->error=1;
if($form->required==1)
{
@ -339,6 +339,28 @@ class ModelForm {
return [$arr_form, false];
}
/**
*
* Get errors from forms array
*
* With this method you can extract an array with errors from forms array
*
* @param array $arr_form is an array of ModelForms. The key of each item is the name of the ModelForm item.
*/
static public function get_errors($arr_form) {
$errors=[];
foreach($arr_form as $form) {
$errors[$form->name]=$form->std_error;
}
return $errors;
}
/**
*
@ -455,13 +477,13 @@ class ModelForm {
}*/
static public function show_form($arr_form, $post, $pass_values=false, $check_values=false, $keys_form=[])
static public function show_form($arr_form, $post, $pass_values=false, $check_values=false, $keys_form=[], $show_error=1)
{
if($pass_values)
{
$arr_form=ModelForm::set_values_form($arr_form, $post, $show_error=1);
$arr_form=ModelForm::set_values_form($arr_form, $post, $show_error);
}
@ -522,7 +544,7 @@ class ModelForm {
$label_class=$arr_form[$field]->label_class;
?>
<p>
<label class="<?php echo $label_class; ?>"><?php echo ucfirst(str_replace('_', ' ', $arr_form[$field]->label) );?> <?php echo $arr_required[$arr_form[$field]->required]; ?> <span class="error"><?php echo $arr_form[$field]->std_error; ?></span>: </label>
<label class="<?php echo $label_class; ?>"><?php echo ucfirst(str_replace('_', ' ', $arr_form[$field]->label) );?> <?php echo $arr_required[$arr_form[$field]->required]; ?> <span class="error" id="<?=$field;?>_error"><?php echo $arr_form[$field]->std_error; ?></span>: </label>
<?php
echo $arr_form[$field]->form();