public function testExistsField() { // setup $frm = new SpoonForm('name', 'action'); $frm->addButton('submit', 'submit'); // checks $this->assertTrue($frm->existsField('submit')); $this->assertFalse($frm->existsField('custom_field')); }
/** * Adds a button to the form * * @param string $name Name of the button. * @param string $value The value (or label) that will be printed. * @param string[optional] $type The type of the button (submit is default). * @param string[optional] $class Class(es) that will be applied on the button. * @return SpoonFormButton */ public function addButton($name, $value, $type = 'submit', $class = null) { $name = (string) $name; $value = (string) $value; $type = (string) $type; $class = $class !== null ? (string) $class : 'inputText inputButton'; // do a check, only enable this if we use forms that are submitted with javascript if ($type == 'submit' && $name == 'submit') { throw new FrontendException('You can\'t add buttons with the name submit. JS freaks out when we replace the buttons with a link and use that link to submit the form.'); } // create and return a button return parent::addButton($name, $value, $type, $class); }
/** * Adds a button to the form * * @return SpoonButton * @param string $name Name of the button. * @param string $value The value (or label) that will be printed. * @param string[optional] $type The type of the button (submit is default). * @param string[optional] $class Class(es) that will be applied on the button. */ public function addButton($name, $value, $type = 'submit', $class = null) { // redefine $name = (string) $name; $value = (string) $value; $type = (string) $type; $class = $class !== null ? (string) $class : 'inputButton'; // do a check if ($type == 'submit' && $name == 'submit') { throw new BackendException('You can\'t add buttons with the name submit. JS freaks out when we replace the buttons with a link and use that link to submit the form.'); } // create and return a button return parent::addButton($name, $value, $type, $class); }
/** * Client Manager * * Login Page to the system. * @package Client Manager * @author Jin Cong<*****@*****.**> */ define('LOAD_TEMPLATE', true); define('LOAD_HEADER', true); define('IN_LOGIN', true); require 'loader.php'; //create new SpoonForm $frm = new SpoonForm('login'); //create form element $frm->addText('adminname'); $frm->addPassword('adminpw'); $frm->addButton('submit', 'Submit'); if ($frm->isSubmitted()) { if ($frm->getField('adminname')->getValue() == ADMINNAME && $frm->getField('adminpw')->getValue() == ADMINPASSWORD) { $_SESSION['logined'] = true; $_SESSION['adminname'] = $frm->getField('adminname')->getValue(); $_SESSION['adminpw'] = $frm->getField('adminpw')->getValue(); $_SESSION['expired'] = time() + ADMINEXPIRED; header('Location: ' . BASE_URL . '/'); $tpl->assign('tooltip', 'Login Success! System will auto redirect you to front page, <a href="' . BASE_URL . '/index.php">click here if not</a>.'); } else { $tpl->assign('tooltip', 'Admin name or Admin password is not correct!'); } } $frm->parse($tpl); $tpl->display(ROOT_PATH . '/' . TEMPLATE_PATH . '/login.tpl.php');