demo.php 740 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App;
  3. use FormBuilder\Factory\Elm;
  4. use FormBuilder\Form\IviewForm;
  5. require '../vendor/autoload.php';
  6. $action = '/save.php';
  7. $method = 'POST';
  8. $input = Elm::input('goods_name', '商品名称')->required();
  9. $textarea = Elm::textarea('goods_info', '商品简介');
  10. $switch = Elm::switches('is_open', '是否开启')->activeText('开启')->inactiveText('关闭');
  11. //创建表单
  12. $form = (new IviewForm($action))->setMethod($method);
  13. //添加组件
  14. $form->setRule([$input, $textarea]);
  15. $form->append($switch);
  16. $form->formData([
  17. 'goods_name' => 'goods_name123',
  18. 'asdf' => 'asdfafd',
  19. 'is_open' => '0'
  20. ])->setValue('goods_info', "asdf\r\nadfa");
  21. //生成表单页面
  22. $formHtml = $form->view();
  23. echo $formHtml;