Jump to content

if isset ... Display another Upload Field


louisstephens

Recommended Posts

Alrighty,

 

I come to you all with another question.

 

So far I have a form with a file upload, and a button under it that says "add" (to add another picture). I simply would like once the "add" button is clicked, for another upload field to "appear" under the previous one using php.  It seemed pretty straight forward to me, but I can not figure it out

Link to comment
https://forums.phpfreaks.com/topic/149918-if-isset-display-another-upload-field/
Share on other sites

<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <label>
    <input type="file" name="u1" id="u1" />
  </label>
  <label>
    <input type="submit" name="add" id="add" value="add" />
  </label>
</form>

<?php


if (isset($_POST['add']))

{

echo <label>
    <input type="file" name="u2" id="u2" />
  </label>

?>




if you do that with PHP, the window will be refreshed. So the upload fields will be reset too. The proper way of doing this is, using javascript. Put all your content in a certain div

 

<div id="certain_div"><input uploadfield blabla><button onclick="addfield();"></div>
function addfield(){
var holder = document.getElementById('certain_div');
holder.innerHTML += '<another uploadfield>';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.