} }); $form->addPasswordField('confirm_password')->label('Confirm Password')->validator(function ($value) use($form) { //example of using another field's value in a field validator via the USE keyword if ($value != $form->getField('password')->getSubmittedValue()) { return 'Password Confirmation did not match password'; } }); /* submit */ $form->addButton('submit')->label('Submit')->action(function ($form) { if ($form->isValid()) { if (rand(1, 10) <= 5) { $form->addError('We have decided to randomly reject your registration. Sorry!'); return false; } else { return true; } } }); $form->addButton('login')->label('or Login')->action(function ($form) { //dont't validate - we don't care if the form is valid header('Location:/some-login-page.php'); exit; }); /* process form if submitted */ if ($form->handleButtonActions()) { echo 'Thank You, ' . $form->getField('email')->getSubmittedValue(); } /* output form */ echo $form->render();