user188962
user188962

Reputation:

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

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 may 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

Upvotes: 0

Views: 150

Answers (2)

Paul Weber
Paul Weber

Reputation: 6688

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...

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382656

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.

Upvotes: 1

Related Questions