Skip to content

Instantly share code, notes, and snippets.

@jbroadway
Created April 4, 2012 23:18
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 jbroadway/2306494 to your computer and use it in GitHub Desktop.
Save jbroadway/2306494 to your computer and use it in GitHub Desktop.
Custom validation of an array of values in Elefant framework.
; <?php /*
[name]
callback = validate_array_not_empty
; */ ?>
<?php
/**
* Custom validation function to test a list of
* values to make sure they're all not empty.
*/
function validate_array_not_empty ($value) {
$names = is_array ($_POST['name']) ? $_POST['name'] : array ($_POST['name']);
foreach ($names as $name) {
if (empty ($name)) {
return false;
}
}
return true;
}
// And the form...
$form = new Form ('post', $this);
echo $form->handle (function ($f) {
info ($_POST, true);
});
?>
<form method="post" id="{{ _form }}">
<p>Name:<br />
<input type="text" name="name[]" value="{{ name[0]|quotes }}" /><br />
<input type="text" name="name[]" value="{{ name[1]|quotes }}" /><br />
<input type="text" name="name[]" value="{{ name[2]|quotes }}" />
<span id="name-notice" class="notice"><br />Names must not be blank.</span>
</p>
<p><input type="submit" value="Submit" /></p>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment