如何在Drupal表单API上填充字段

如何在Drupal表单API上填充字段,drupal,Drupal,我有一个DrupalAPI的形式 function contactus(){ return drupal_get_form('myform_contact'); } function myform_contact($form_state){ $form['field'] = array( '#type' => 'fieldset', '#title' => 'Contact Us Form', '#collapsible' =>

我有一个DrupalAPI的形式

  function contactus(){
    return drupal_get_form('myform_contact');
  }

function myform_contact($form_state){
    $form['field'] = array(
    '#type' => 'fieldset',
    '#title' => 'Contact Us Form',
    '#collapsible' => true,
    '#collapsed'=> false,
    '#description' => t('Enter your feedback'),
    );

    $form['field']['email']  = array(
    '#type'=>'textfield',
    '#title'=> 'E-mail Address',
    '#required' => '0',
    '#maxlength' => 127,
    '#required' => 0,
    );

    $form['field']['comment'] = array(
    '#type'=> 'textarea',
    '#rows'=> 5,
    '#title' => 'Comment / Question? ',
    '#required' =>1,     
    );

    $form['field']['captcha'] = array(
    '#type' => 'captcha',
    '#captcha_type' => 'image_captcha/Image',

    );

    $form['field']['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
    '#validate' => array('form_validate'),
    '#weight' => 1
    );
    $form['field']['edit'] = array(
    '#type'=> 'button',
    '#value' => 'Edit',
    '#validate'=> array('form_edit'),
    '#weight' => 10,
    );

    return $form;
}

function myform_contact_submit($form, &$form_state){

    $txt = $form_state['values']['comment'];
    $email = $form_state['values']['email'];
    $txt = wordwrap($txt,70);
    mail("$email", "Comment / Questions ?", $txt);
    $result = db_query("insert into contactus values('$email','$txt')");
    $node = new stdClass();
    $node-> title = $form_state['values']['email'];
    $node-> body = $form_state['values']['comment'];
    $node->type = 'contactus';
    node_save($node);
    drupal_set_message(t('Form Successfully submitted with nid of '. $node->nid));
    drupal_set_message(t('Values inserted into Database'));
}

function form_edit($form,&$form_state){
   $nid = $form_state['values']['nid'];
   $node = node_load(49);
   drupal_set_message('edit mode with title '. $node->title. ' and comment as '. $node->body);
   $form_state['values']['email'] =  $node->title;
   $form_state['values']['comment'] = $node->body;     
}

在编辑时,我想用这些值填充表单字段。然而,它并没有普及。有什么想法吗?

据我所知,FAPI没有表单编辑类型的钩子。通常有表单定义函数、验证函数和提交函数。如果还没有,请查看文档


在我看来,您需要将“#default_value”属性添加到要填充的表单元素中。您还需要将加载节点的任何代码移动到myform\u contact函数中。

能否给出一个工作示例,说明如何使用drupal\u execute($form\u id,$form\u state)实现表单填充?