开发者

Populate a textarea in a form before rendering with Drupal 7

I am new to writing Drupal forms, and having trouble in what seems the simplest thing of the whole process form namely putting data in a textarea on the form before rendering.

  • I am using drupal 7
  • I have all necessary files in the module: i.e. .module, and .info ..
  • I have used all of these function in my hook_submit() but to no avail.

    Form_state['values'][$myElement=]= $myText;
    Form_state[$myElement=]= $myText;
    form_set_value($form[$myElement], t('$myText'), $form_state);
    
  • I flushed the cache before every single attempt:

Nothing seems to work. Here is what is in my submit handler:

mForm_submit(){
//$form_state['values']['sku_output_fieldset']['sku_output'] = t('$gen_sku_txt');
//$form_state['gen_sku']['sku_output_fieldset']['sku_ou开发者_JS百科tput'] = t('$gen_sku_txt');
//$form['sku_output_fieldset']['sku_output']['#value'] = t('$gen_sku_txt');
//form_set_value($form['sku_output_fieldset']['sku_output'], t('$gen_sku_txt'), $form_state);
//form_set_value($form['sku_output'], t('$gen_sku_txt'), $form_state);
//form_set_value($form['sku_output'], array('rgb' => '123'), $form_state);
//form_set_value($form['sku_output_fieldset']['sku_output'], array('#default_value' => '123'), $form_state);
//form_set_value($form['sku_output_fieldset']['sku_output'], array('#value' => '123'), $form_state);
//form_set_value($form['sku_output_fieldset']['sku_output'], array('value' => '123'), $form_state);
//form_set_value($form['sku_output_fieldset']['sku_output'], array('default_value' => '123'), $form_state);

$form_state['rebuild'] = TRUE;
}

all commented code, is what i have tried and did not work.


Are you building the form with Drupal 7 Form API? This is how I've inserted default text into a textarea in a Drupal form:

$form['formname_fieldname'] = array(
  '#default_value' => t('Some default text'),
  '#title' => t('Field Title'),
  '#type' => 'textarea',
  '#required' => FALSE,
  '#rows' => 10,
);

Your textarea will be prepopulated with "Some default text"


If you want to change it before rendering, you shouldn't have in a submit function.

You should use hook_form_alter(&$form, &$form_state, $form_id) where the $form being passed in is the variable you can use to edit the form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜