Drupal Form:want to show previous form value as default_value on page

后端 未结 8 1506
春和景丽
春和景丽 2020-12-31 20:57

My Goal is if user is submitting this form with \"Product Name\" value as \"YYY\". On submit page should reload but this time \"Product Name\" should show previous valye as

8条回答
  •  [愿得一人]
    2020-12-31 21:48

    Not sure if this would work for you, but you could try adding the #default_value key to the form array

    $form['productname'] = array (
    '#type' => 'textfield',
    '#title' => t('Product Name'),
    '#required' => TRUE,
    '#size' => '20',
    '#default_value' => variable_get('productname', ''),
    );
    

    That way if the variable is set it will grab whatever it is, but if not you can use a default value.

提交回复
热议问题