Skip to content

Commit

Permalink
338: fix validator problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Atmos4 committed Dec 14, 2024
1 parent be2505b commit d37ccb5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions engine/validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class Validator
function __construct(array $form_values = [], $action = null)
{
$this->action = $action;
$_POST['action'] ??= null;
if ((!empty($_POST) or !empty($_FILES)) and ((!$action && !$_POST['action']) or $_POST['action'] == $action)) {
if ((!empty($_POST) or !empty($_FILES)) and ((!$action && !isset($_POST['action'])) or $_POST['action'] == $action)) {
$this->empty = false;
$form_values = $_POST;
}
Expand Down Expand Up @@ -52,9 +51,11 @@ function get_field(string $key): Field
* To be used with a standalone hx-post / hx-delete
* @return string
*/
function hx_action(): string
function hx_action($vals = []): string
{
return "hx-vals='{\"action\":\"$this->action\",\"csrf\":\"" . gen_csrf() . "\"}'";
$vals["action"] = $this->action;
$vals["csrf"] = gen_csrf();
return "hx-vals='" . json_encode($vals) . "'";
}

function render_validation(): string
Expand Down

0 comments on commit d37ccb5

Please sign in to comment.