Field validate required AND unique

Field validate required AND unique

crush123crush123 Posts: 417Questions: 126Answers: 18
edited September 2015 in Editor

I have an email address in my editor instance which I want to be required and unique.

Field::inst( 'tblpatron.EmailAddress' )
    ->validator( 'Validate::unique', array(
            "required"  => true,
            "message" => "This email address is already in use"
        ) )

How can I set the message so that if the field is left empty, i get the 'required' message and if it is a duplicate, I get a different 'unique' message ?

Thanks

Answers

  • crush123crush123 Posts: 417Questions: 126Answers: 18
    edited September 2015

    Ok, I think I've sorted it.

    I just called the validation function twice

    Field::inst( 'tblpatron.EmailAddress' )
            ->validator( 'Validate::unique', array(
                "message" => "This email address is already in use"
            ) )
            ->validator( 'Validate::required', array(
                "message" => "An email address is required"
            ) ),
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Yup - perfect. Thanks for posting back.

    Allan

  • poorvipoorvi Posts: 1Questions: 0Answers: 0

    thanks. its very helpful

This discussion has been closed.