Fix Form_Utils to use component.$sid() instead of data-sid selector

Add response helper functions and use _message as reserved metadata key

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-23 22:38:48 +00:00
parent 678ff17ad6
commit 69af4e87d4
5 changed files with 73 additions and 14 deletions

View File

@@ -1089,6 +1089,57 @@ function response_not_found(?string $message = null)
return response_error(\App\RSpade\Core\Ajax\Ajax::ERROR_NOT_FOUND, $message);
}
/**
* Create a form validation error response
*
* Use this for validation errors with field-specific messages.
* The client-side form handling will apply errors to matching fields.
*
* @param string $message Summary message for the error
* @param array $field_errors Field-specific errors as ['field_name' => 'error message']
* @return \App\RSpade\Core\Response\Error_Response
*/
function response_form_error(string $message, array $field_errors = [])
{
return response_error(
\App\RSpade\Core\Ajax\Ajax::ERROR_VALIDATION,
array_merge(['_message' => $message], $field_errors)
);
}
/**
* Create an authentication required error response
*
* Use this when the user is not logged in and needs to authenticate.
* Distinct from response_unauthorized() which is for permission denied.
*
* @param string|null $message Custom error message (optional)
* @return \App\RSpade\Core\Response\Error_Response
*/
function response_auth_required(?string $message = null)
{
return response_error(\App\RSpade\Core\Ajax\Ajax::ERROR_AUTH_REQUIRED, $message);
}
/**
* Create a fatal error response
*
* Use this for unrecoverable errors that prevent the operation from completing.
* These are typically logged and displayed prominently to the user.
*
* @param string|null $message Error message
* @param array $details Additional error details (e.g., file, line, backtrace)
* @return \App\RSpade\Core\Response\Error_Response
*/
function response_fatal_error(?string $message = null, array $details = [])
{
$metadata = $details;
if ($message !== null) {
$metadata['_message'] = $message;
}
return response_error(\App\RSpade\Core\Ajax\Ajax::ERROR_FATAL, $metadata ?: $message);
}
/**
* Check if the current request is from a loopback IP address
*