patch submit...

main
Robert 2 months ago
parent 13af47ae5c
commit f58db708eb
  1. 9
      protected/src/inputs/app/home_in.php
  2. 33
      protected/src/outputs/app/home_out.php
  3. 24
      protected/src/views/twig/app/val_tests.html.twig

@ -34,9 +34,12 @@ class home_in {
public static function val_tests(object $app): array { public static function val_tests(object $app): array {
$posts_data = $app->request->get_post_data(); $posts_data = $app->request->get_post_data();
$i_age = intval($posts_data->get("age"));
$age = ($i_age > 0) ? $i_age : null;
$user_test_data = new my_val_tests_form( $user_test_data = new my_val_tests_form(
$posts_data->get("name"), $posts_data->get("name"),
intval($posts_data->get("age")), $age,
$posts_data->get("email") $posts_data->get("email")
); );
@ -54,12 +57,14 @@ class home_in {
$adult_post_int_age_field = new IO(); $adult_post_int_age_field = new IO();
$adult_post_int_age_field->input_type = INPUTS::post; $adult_post_int_age_field->input_type = INPUTS::post;
$adult_post_int_age_field->field_filter = FIELD_FILTER::integer_number; $adult_post_int_age_field->field_filter = FIELD_FILTER::integer_number;
$adult_post_int_age_field->validation_rule = 'greater_than: 18'; $adult_post_int_age_field->validation_rule = 'greater_than: 17';
$adult_post_int_age_field->validation_message = ['greater_than' => 'The %s must be an Adult over %d!']; $adult_post_int_age_field->validation_message = ['greater_than' => 'The %s must be an Adult over %d!'];
$email_field = self::define_io('required|max: 255'); $email_field = self::define_io('required|max: 255');
return [ return [
'method' => $app->request->get_method(),
'headers' => ['Full Name', 'Age', 'Email'],
'html' => [ 'html' => [
'name' => $name_field, 'name' => $name_field,
'age' => $adult_post_int_age_field, 'age' => $adult_post_int_age_field,

@ -26,7 +26,13 @@ class home_out {
} }
} }
$one_row[] = $html_output;
$did_submit = ($input['method'] === "POST");
$data = [ $data = [
'did_submit' => $did_submit,
'headers' => $input['headers'],
'user' => $one_row,
'safe_html' => $html_output, 'safe_html' => $html_output,
'post_data' => $input['post_data'], 'post_data' => $input['post_data'],
'a_errors' => array_merge($input['a_errors'], $errors), 'a_errors' => array_merge($input['a_errors'], $errors),
@ -36,34 +42,11 @@ class home_out {
...$data ...$data
]); ]);
$app->view->set('twig_functions', [ $app->view->set('twig_functions', [
'show_user_details' => '\Project\outputs\app\home_out::show_user_details', 'show_table' => '\CodeHydrater\html::show_table',
'show_errors' => '\Project\outputs\app\home_out::show_errors', 'show_errors' => '\CodeHydrater\html::show_errors',
]); ]);
$content = $app->view->fetch($app, "app/val_tests.html", ViewType::TWIG); $content = $app->view->fetch($app, "app/val_tests.html", ViewType::TWIG);
$app->response->set_content($content); $app->response->set_content($content);
return []; return [];
} }
public static function show_errors(?array $errors = []): void {
if ($errors) {
$message = "Please correct the following errors: ";
$i = 0;
foreach($errors as $error) {
$i++;
$message .= "<br/>{$i}) " . $error;
}
echo $message;
}
}
public static function show_user_details(array $input): void {
$rows[] = $input; // Force one rows
\CodeHydrater\html::show_table(
['Full Name', 'Age', 'Email'],
$rows,
escape: false
);
}
} }

@ -5,28 +5,34 @@
</head> </head>
<body> <body>
<h1>Welcome!</h1> <h1>Welcome!</h1>
{% if post_data.name %}
{{ show_user_details(safe_html) }} {% if did_submit and a_errors is empty %}
{{ show_table(headers, user, false) }}
<p>{{ safe_html.name }}, you Rock!</p>
{% if a_errors %}
<h2>Errors Reporeted, are:</h2>
{{ show_errors(a_errors) }}
{% endif %}
{% else %} {% else %}
{% if did_submit and a_errors %}
<h2 style="color: red;">Errors Reporeted, are:</h2>
<div style="color: darkred"> {{ show_errors(a_errors) }} </div>
<hr>
{% endif %}
<form method="POST"> <form method="POST">
<table> <table>
<tr> <tr>
<td><label for="name">Your full name</label></td> <td><label for="name">Your full name</label></td>
<td><input type="text" name="name" id="name"></td> <td><input type="text" name="name" id="name" value="{{ post_data.name }}" ></td>
</tr> </tr>
<tr> <tr>
<td><label for="age">Age</label></td> <td><label for="age">Age</label></td>
<td><input type="number" name="age" id="age"></td> <td><input type="number" name="age" id="age" value="{{ post_data.age }}"></td>
</tr> </tr>
<tr> <tr>
<td><label for="email">Email Address</label></td> <td><label for="email">Email Address</label></td>
<td><input type="email" name="email" id="email"></td> <td><input type="email" name="email" id="email" value="{{ post_data.email }}"></td>
</tr> </tr>
<tr> <tr>
<td colspan="2" style="text-align: center;"> <td colspan="2" style="text-align: center;">

Loading…
Cancel
Save