new IO class

main
Robert 3 years ago
parent 2721f8ae64
commit ea976c3779
  1. 39
      src/mockup/go_text_templates/inputs.txt
  2. 4
      src/mockup/go_text_templates/outputs.txt
  3. 51
      src/mockup/inputs/app/home_in.php
  4. 4
      src/mockup/outputs/app/home_out.php

@ -11,29 +11,28 @@ use \tts\DB_FILTER;
class {{.File}}_in {
/*
* Validation_rules: required, email, valid_email_domain,
* min, max, between, same, secure (password), alphanumeric
* number_range: X, X
* greater_than
* less_than
*/
public static function {{.Method}}(): array {
\tts\safer_io::init_json(); // Staticly set JSON data if any
$required_post_string_field = new IO();
$required_post_string_field->input_type = INPUTS::post;
$required_post_string_field->field_filter = FIELD_FILTER::raw_string;
$required_post_string_field->escape_html = HTML_FLAG::escape;
$required_post_string_field->validation_rule = 'required|max: 75';
$required_post_string_field->use_db_filter = DB_FILTER::OFF;
$required_post_string_field->skip_the_db = false;
return [
'first_name' =>
[
'input' => INPUTS::post,
'field' => FIELD_FILTER::raw_string,
'html' => HTML_FLAG::escape,
'rule' => 'required|max: 75', // Others: email, valid_email_domain,
// min, max, between, same, secure (password), alphanumeric
'message' => ['required' => 'Must fill out first_name!'],
'db' => DB_FILTER::OFF, // Should be used on Login Data only
'skip_db' => false // Should not save?
],
'last_name' =>
[
'input' => INPUTS::post,
'field' => FIELD_FILTER::raw_string,
'html' => HTML_FLAG::escape,
'rule' => 'required|max: 75',
'message' => ['required' => 'Must fill out last_name!'],
'db' => DB_FILTER::OFF // Should be used on Login Data only
],
'first_name' => $required_post_string_field,
'last_name' => $required_post_string_field
];
}

@ -10,11 +10,11 @@ class {{.File}}_out {
public static function {{.Method}}(array & $input): array {
$ret['model'] = $input['model'];
unset($input['model']); // Required to work, as sanitize cannot take an Object
unset($input['model']); // Free up some space
$html_output = [];
$errors = [];
foreach(SafeIO::html_sanitize($input) as $html) {
foreach(SafeIO::html_escape_and_sanitize($input) as $html) {
$key = $html['name'] ?? "";
$html_output[$key] = $html['html'];

@ -8,36 +8,39 @@ use \tts\INPUTS;
use \tts\FIELD_FILTER;
use \tts\HTML_FLAG;
use \tts\DB_FILTER;
use tts\use_io as IO;
class home_in {
/*
* Validation_rules: required, email, valid_email_domain,
* min, max, between, same, secure (password), alphanumeric
* number_range: X, X
* greater_than
* less_than
*/
public static function name_demo(): array {
\tts\safer_io::init_json(); // Staticly set JSON data if any
$required_post_string_field = new IO();
$required_post_string_field->input_type = INPUTS::post;
$required_post_string_field->field_filter = FIELD_FILTER::raw_string;
$required_post_string_field->escape_html = HTML_FLAG::escape;
$required_post_string_field->validation_rule = 'required|max: 75';
$required_post_string_field->use_db_filter = DB_FILTER::OFF;
$required_post_string_field->skip_the_db = false;
$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_message = ['greater_than' => 'The %s must be an Adult over %d!'];
return [
'first_name' =>
[
'input' => INPUTS::post, // Others: post, json (REQUIRED param)
'field' => FIELD_FILTER::raw_string, // Others: raw, (DEFAULT: string), email, url, float, int
'html' => HTML_FLAG::purify, // Others: strip, encode, purify, (DEFAULT: escape)
'rule' => 'required|max: 75', // Others: email, valid_email_domain,
// min, max, between, same, secure (password), alphanumeric
'db' => DB_FILTER::OFF // Should be used on Login Data only
],
'last_name' =>
[
'input' => INPUTS::post,
'field' => FIELD_FILTER::raw_string,
'html' => HTML_FLAG::purify,
'rule' => 'required|max: 75',
'skip_db' => false
],
'age' =>
[
'input' => INPUTS::post,
'field' => FIELD_FILTER::integer_number,
'rule' => 'greater_than: 18', //'number_range: 18, 24'
'message' => ['greater_than' => 'The %s must be an Adult over %d!'],
],
'first_name' => $required_post_string_field,
'last_name' => $required_post_string_field,
'age' => $adult_post_int_age_field
];
}

@ -10,11 +10,11 @@ class home_out {
public static function name_demo(array & $input): array {
$ret['model'] = $input['model'];
unset($input['model']); // Required to work, as sanitize cannot take an Object
unset($input['model']); // Free up some space
$html_output = [];
$errors = [];
foreach(SafeIO::html_sanitize($input) as $html) {
foreach(SafeIO::html_escape_and_sanitize($input) as $html) {
$key = $html['name'] ?? "";
$html_output[$key] = $html['html'];

Loading…
Cancel
Save