Skip to content

Instantly share code, notes, and snippets.

@jbroadway
Created March 29, 2012 23:39
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/2244952 to your computer and use it in GitHub Desktop.
Save jbroadway/2244952 to your computer and use it in GitHub Desktop.
Example custom form validation in Elefant
<?php
class Author extends Model {
public static function unique_name ($value) {
$res = Author::query ()
->where ('first_name', $_POST['first_name'])
->where ('last_name', $_POST['last_name'])
->count ();
if ($res > 0) {
return false;
}
return true;
}
}
?>
; <?php /*
[first_name]
not empty = 1
callback = "Author::unique_name"
[last_name]
not empty = 1
; */ ?>
<?php
$form = new Form ('post', $this);
echo $form->handle (function ($form) {
info ($_POST);
});
?>
<form method="POST" id="{{ _form }}">
<p>{"First Name"}:<br /><input type="text" name="first_name" value="{{ first_name|quotes }}" />
<span class="notice" id="first_name-notice">{"The name is required and must be unique."}</span></p>
<p>{"Last Name"}:<br /><input type="text" name="last_name" value="{{ last_name|quotes }}" />
<span class="notice" id="last_name-notice">{"Please enter the author's last name."}</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