Beispiel #1
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 *
 * @author Marien den Besten
 */
include '../src/Loader.php';
use FormHandler\FormHandler;
use FormHandler\Field;
use FormHandler\Button;
use FormHandler\Validator;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
$form = new FormHandler();
Field\File::set($form, 'Upload file', 'upload_file')->setDropZoneEnabled(true, 'Drop your custom file here');
Field\Text::set($form, 'Text field', 'some_other_field')->setValidator(new Validator\String());
$form->_setJS('FormHandler.registerHandlerUploaded(\'upload_file\', function(){ alert(\'File uploaded\'); });', false, true);
Button\Submit::set($form, 'Submit 1');
$form->onCorrect(function ($data) {
    echo '<pre>';
    var_dump($_POST);
    var_dump($data);
    if (is_object($data['upload_file'])) {
        echo "\n" . $data['upload_file']->getRealpath();
    }
    echo '</pre>';
    return true;
});
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 *
 * @author Marien den Besten
 */
include '../src/Loader.php';
use FormHandler\FormHandler;
use FormHandler\Field;
use FormHandler\Button;
use FormHandler\Validator;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
\FormHandler\Configuration::set('default_disable_submit_btn', true);
$form = new FormHandler();
for ($i = 1; $i <= 15; $i++) {
    Field\Text::set($form, 'Field ' . $i, 'field_' . $i)->setDefaultValue('Value ' . $i);
}
Button\Submit::set($form, 'Submit 1')->onClick(function () {
    echo 'Submit 1 clicked';
});
Button\Submit::set($form, 'Submit 2')->onClick(function () {
    echo 'Submit 2 clicked';
});
//process all form results, needs to be done before any output has been done
$form_html = $form->flush();
//below is code to show the form
echo 'Test for disabled buttons on submit<hr>';
echo $form_html;