开发者

Html POST and return the same form with the values

开发者 https://www.devze.com 2022-12-30 18:17 出处:网络
I\'m learning web development, and I don\'t know how do this simple thing. I\'ve a html form with \"text\", \"radio\" and \"checkbox\" controls, that POST the values to the server and it saves them,

I'm learning web development, and I don't know how do this simple thing.

I've a html form with "text", "radio" and "checkbox" controls, that POST the values to the server and it saves them, for example in a file. I save the POST in raw format:

key=value&key=value&key=value&key=value

and I'd like that when the user ope开发者_开发知识库n the form back, return the form with the saved values already in the controls.

Is there any neat way to do this? Or should I parse the POST string and set the values one by one in the controls at the server level?

I think, I could return the saved data in a hidden input control, and after with a javascript I could do a getElementById(key) and set the value to each input control... but do I need to put the post string in a special format?

How would you do it?

Thank you in advance.


You should store the POST fields (preferably not in querystring style, your programming language probably has some serialization functions which are better for that) and then fill the form fields by setting value="..." attributes (or tag content e.g. for textareas).


What server side language are you using ? If php :
< ?php $myvar = $_POST['myvar'] ?>

<input type="text" value="<?php echo $myvar; ?>" />

0

精彩评论

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