-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm going to cut out a bit of this to make it simpler, but here is a
section of the code behind my users->signup page, and the
corresponding validation model.

VIEW:
create('User', array('action' => 'signup')); ?>




input('User/username', array('between' => ':
', 'id' => 'focus')); ?>





input('User/email', array('between' => ':
')); ?>





end('Register'); ?>





and:
MODEL:
        var $validate = array(

'username' => array(

'alphanumeric' => array(

'rule' => array('custom', '/[a-z0-9\_\-]$/i'),

'required' => true,

'message' => 'Username must be a-z, 0-9, plus "_", "-", " "'

),

'between' => array(

'rule' => array('between', 5, 30),

'message' => 'Between 5 and 30 characters'

),

'checkUnique' => array(

'rule' => array('checkUnique', 'username'),

'message' => 'Username is in use. Choose another.'

)

),

'password' => array(

'rule' => array('minLength', '6'),

'message' => 'Minimum 6 characters'

),

'email' => array(

'valid' => array(

'rule' => array('email', true),

'message' => 'Please use a valid E-Mail address'

),

'checkUnique' => array(

'rule' => array('checkUnique', 'email'),

'message' => 'E-mail is already being used. Choose another.'

)

),

      )
        /*function to check that
entered data is not currently present in the database*/
        function checkUnique($data,
$fieldName)
        {

$valid = false;

if(isset($fieldName) && $this->hasField($fieldName))

{

$valid = $this->isUnique(array($fieldName => $data));

}

return $valid;
        }

The first username rule "alphanumeric" is a custom rule which searches
for letters, numbers, dashes, underscores, and spaces as valid
characters, and if anything else is present, throws a validation
error.
The second username rule "between", checks for both minimum and
maximum values. To change it to maxValue only, you would change it to
this:
'between' => array(

'rule' => array('MaxLength', 30),

'message' => 'Between 5 and 30 characters'

)

The third username rule, 'isUnique', simply uses the isUnique()
function in CakePHP 1.2 to find out if the entered username is already
in use or not.

The password field simpy has a minimum length requirement.

The email rule uses the builtin email verification validation
function, and the isUnique() funciton to check for pre-used emails
again.


Hope this helps! If you (or anyone else) has any questions, feel free to
ask!


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: http://firegpg.tuxfamily.org

iD8DBQFHn90A07DvTednSKQRAj5TAJ0Ricqhc4t6vGmf0LAOllP73vM2/QCfYrWZ
JO/Dc+5flmsjMslfcV6WiLs=
=lm4P
-----END PGP SIGNATURE-----
On Jan 29, 2008 5:07 PM, red <[EMAIL PROTECTED]> wrote:

>
> Why just don't bake this simple example?
>
>
> On 29 Sty, 22:33, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > Can someone post a simple 1.2 beta example of a form w/ validation?  I
> > have tried all kinds of examples on various sites, but none work.  I'd
> > like to see the view for a simple form, and the corresponding
> > controller and model.  If the validation could show an example of
> > required and maxLength rules with displaying error messages I would
> > really appreciate it.  Thanks.
> >
>


-- 
In the name of Life, Liberty, and the pursuit of my sanity.
Siebren Bakker(Aevum Decessus)
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d- s+: a19 C++++ UL++ P L++
!E W++ N(-) o? K? w(+) O? M-- V?
PS+ PE Y- PGP- t+ 5? X- R tv--
b++ Di D+ G+ e h! r y-
------END GEEK CODE BLOCK------

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to