Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mzur
Last active September 11, 2015 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzur/f3f1ff18ff8b4ad87fbb to your computer and use it in GitHub Desktop.
Save mzur/f3f1ff18ff8b4ad87fbb to your computer and use it in GitHub Desktop.
Old version of the AJAX response template (http://blog.the-inspired-ones.de/ajax-uniform)
<?php
header::contentType('application/json');
$errors = '';
// check each parameter of the request if it is erroneous
foreach (array_keys(get()) as $field) {
$errors .= $form->hasError($field) ? "\"$field\"," : '';
}
// strip trailing comma
$errors = substr($errors, 0, -1);
?>
{
"success": <?php e($form->successful(), 'true', 'false')?>,
"message": "<?php echo trim($form->message()) ?>",
"errors": [<?php echo $errors ?>]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment