0
領域我有形式如何填充在Drupal的形式API
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;
}
在編輯我想填充值的表單字段的Drupal的API。但是,它不是填充。有任何想法嗎??
你能給我一個工作的例子,說明如何使用drupal_execute($ form_id,$ form_state)來實現表單填充嗎? – user544079 2010-12-17 04:59:01