hunter_form_submit

参数

{array} parms

{string} module

{string} result

用法

重要的form api, 一般写在Controller中,用于将此表单提交返回的结果挂载在钩子上,以便其他模块扩展,这是官方推荐写法。

像这样使用:

use Zend\Diactoros\ServerRequest;

  /**
   * page_add.
   *
   * @return string
   *   Return page_add string.
   */
  public function page_add(ServerRequest $request) {
    if ($parms = $request->getParsedBody()) {
      $title = $parms['title'];
      $content = $parms['content'];
      $status = $parms['status'];

      $pid = db_insert('page')
        ->fields(array(
          'title' => $title,
          'content' => $content,
          'status' => $status,
          'created' => time(),
          'updated' => time(),
        ))
        ->execute();

      return hunter_form_submit($parms, 'page', $pid);
    }

    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => '标题',
      '#maxlength' => 11,
    );
    $form['content'] = array(
      '#type' => 'textarea',
      '#title' => '内容',
      '#attributes' => array('id' => 'content', 'lay-verify' => 'content'),
    );
    $form['status'] = array(
      '#type' => 'radios',
      '#title' => '状态',
      '#default_value' => '1',
      '#options' => array('1' => '发布', '0' => '草稿')
    );
    $form['save'] = array(
     '#type' => 'submit',
     '#value' => '保存',
     '#attributes' => array('lay-filter' => 'pageAdd', 'lay-submit' => ''),
    );
    $form['form_id'] = 'page_add_form';

    return view('/admin/page-add.html', array('form' => $form));
  }

HunterPHP - 用心与你沟通