开发者

How to save information in inputs inside a form so it doesn't disappear when form is submitted to itself?

开发者 https://www.devze.com 2022-12-15 00:54 出处:网络
I have a picture upload inside a form... The file is a php file btw... Problem is whenever this form is filled in, and the user clicks to upload the first picture, the form is submitted to itself an

I have a picture upload inside a form... The file is a php file btw...

Problem is whenever this form is filled in, and the user clicks to upload the first picture, the form is submitted to itself and all the fields which the user m开发者_StackOverflow中文版ay have filled in will go blank...

I know of one way to do it, alot of 'isset' in my php code, but is there any simpler or maybe better way I don't know of?

Thanks


You echo back the POST variable on your fields.

<form method="POST">
  <input type="text" name="name" value="<?php echo $_POST['name']?>" />
  <input type="submit" name="submit" />
</form>

When the form is submitted to self, the same data will be filled.


Well i do not know of anything else. I always use this:

<input type="text" value="<?= isset($value) ? $value : ""; ?>">

I think it is not too much code in the Templates, but it does the Trick.

Alternatively you could use some Frameworks wich abstract everything for you, but i cannot recommend some...

0

精彩评论

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