patch submit...

main
Robert 2 months ago
parent 13af47ae5c
commit f58db708eb
  1. 9
      protected/src/inputs/app/home_in.php
  2. 35
      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 {
$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(
$posts_data->get("name"),
intval($posts_data->get("age")),
$age,
$posts_data->get("email")
);
@ -54,12 +57,14 @@ class home_in {
$adult_post_int_age_field = new IO();
$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->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!'];
$email_field = self::define_io('required|max: 255');
return [
'method' => $app->request->get_method(),
'headers' => ['Full Name', 'Age', 'Email'],
'html' => [
'name' => $name_field,
'age' => $adult_post_int_age_field,

@ -26,9 +26,15 @@ class home_out {
}
}
$one_row[] = $html_output;
$did_submit = ($input['method'] === "POST");
$data = [
'did_submit' => $did_submit,
'headers' => $input['headers'],
'user' => $one_row,
'safe_html' => $html_output,
'post_data' =>$input['post_data'],
'post_data' => $input['post_data'],
'a_errors' => array_merge($input['a_errors'], $errors),
];
@ -36,34 +42,11 @@ class home_out {
...$data
]);
$app->view->set('twig_functions', [
'show_user_details' => '\Project\outputs\app\home_out::show_user_details',
'show_errors' => '\Project\outputs\app\home_out::show_errors',
'show_table' => '\CodeHydrater\html::show_table',
'show_errors' => '\CodeHydrater\html::show_errors',
]);
$content = $app->view->fetch($app, "app/val_tests.html", ViewType::TWIG);
$app->response->set_content($content);
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>
<body>
<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 %}
{% 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">
<table>
<tr>
<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>
<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>
<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>
<td colspan="2" style="text-align: center;">

Loading…
Cancel
Save