Gusev
Gusev

Reputation: 3

Different labels for input file types in PHP/HTML

I've a really simple problem I can't seem to fix :( .

I have the following PHP variable:

$nrofattachments="2"; 

And in my HTML code I've something like this to show the number of file upload fields:

<?For($i=1;$i <= $nrofattachments; $i++) {?>
   <div class="form-group">
      <label for="attachments" class="control-label">Attachment(s)</label>
      <input name="attachment[]" type="file" id="attachments" size="30"/>
   </div>
<?}?> 

What I want to achieve is different labels for each input file type...

Upvotes: 0

Views: 79

Answers (1)

Hanky Panky
Hanky Panky

Reputation: 46900

<? 
 for($i=1;$i <=$nrofattachments; $i++) 
 {
      echo '<div class="form-group">
      <label for="attachments['.$i.']" class="control-label">Attachment '.$i.'</label>
      <input name="attachment['.$i.']" type="file" id="attachments['.$i.']" size="30"/>
      </div>';
  }
?>

Upvotes: 1

Related Questions