Only show file field on edit form if no data present

networkx 22 Mar, 2015
I am working on an edit form that has a total of 7 file fields (for uploading up to 7 pictures to a particular record). On the edit form, I have already written a custom code block for each of the 7 that will display the picture that was uploaded along with a link to the picture or will say "No Picture" for any of the 7 fields are empty in the database. I also want the form to only show the File Upload field for any of the 7 that do not currently have a picture in the database. Any ideas on how I should approach this?
GreyHead 23 Mar, 2015
Answer
1 Likes
Hi networks,

The simplest solution would be to add the file input where you have the 'No picture' message displayed. You could presumably add it to the same custom code.

Bob
networkx 23 Mar, 2015
Thanks for the tip! I had been trying to come up with something complicated and forgot I could just call the file input box manually. In case anyone else was trying something similar, here is the code I used and it is working perfectly. Thanks again Bob!

<?php
if (!empty($form->data['cmodels']['mPic1'])) {
echo "<img src='/images/models/".$form->data['cmodels']['mFolder']."/".$form->data['cmodels']['mPic1']."' height='250'><br> <br>";
echo "Link: <a href='/images/models/".$form->data['cmodels']['mFolder']."/".$form->data['cmodels']['mPic1']."'>/images/models/".$form->data['cmodels']['mFolder']."/".$form->data['cmodels']['mPic1']."</a><br>";
} else {
echo 'No Picture<br>';
echo '<div class="form-group gcore-form-row" id="form-row-mPic1"><label for="mPic1" class="control-label gcore-label-left">Picture 1</label>
<div class="gcore-input gcore-display-table" id="fin-mPic1"><input name="cmodels[mPic1]" id="mPic1" class="validate['image'] form-control gcore-height-auto A" title="" style="" multiple="0" data-load-state="" data-tooltip="" type="file" /><span class="help-block">In jpg, or png format. 1 MB max file size, 197w x 295h</span></div></div>';
}
?>
This topic is locked and no more replies can be posted.