开发者

Showing form data after submit

I have a form with a submit button and a handler that stores data in the database. Problem is when the form is submitted, all data is cleared from the input fields. Is there a way to still show them after submit? What changes do I need to make to my form_submit function?

function mymodule_form_submit($form, &$form_state) {
 //how to retain the input in the form
}

开发者_开发技巧I'm looking for the most "drupalish" way to get this done?


As indicated by this previous StackOverflow question you can accomplish this with $form_state['storage'] and $form_state['rebuild'].


You can access the data using $_REQUEST['form_variable_name'] where form_variable_name is the name of the html input tag.

You then need to render the page back putting this value into the input tags value field.

<form method="POST" action="/account/contactdetails/">
 <div>
  <label>First name:</label>
  <input type="text" name="firstname" value="<?php echo $_REQUEST['firstname']; ?>" />
 </div>
 <div>
  <label>Last name:</label>
  <input type="text" name="lastname" value="<?php echo $_REQUEST['lastname']; ?>" />
 </div>
 <input type="submit" value="Save" />
</form>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜