close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Can I show a file upload field on an update form if no file already exists?

Thread began 4/05/2022 2:44 pm by art226587 | Last modified 4/26/2022 2:39 pm by Ray Borduin | 355 views | 10 replies |

art226587

Can I show a file upload field on an update form if no file already exists?

I have an insert form that contains 3 file upload fields. The user doesn't always upload all three files, but I would like them to be able to go back and upload them afterward using the update form. I'm clueless how to a) check if the file exists and b) display the file upload field if it doesn't. Here is the HTML for the update.php form:

<div class="lineGroup"> <label for="file1" class="sublabel" > file 1:</label>
<input name="file1" type="file" id="file1" size="30" tabindex="32" title="Please enter a value.">
</div>
<div class="lineGroup"> <label for="file2" class="sublabel" > file 2:</label>
<input name="file2" type="file" id="file2" size="30" tabindex="33" title="Please enter a value.">
</div>
<div class="lineGroup"> <label for="file3" class="sublabel" > file 3:</label>
<input name="file3" type="file" id="file3" size="30" tabindex="34" title="Please enter a value.">
</div>



Here's what's in my details.php page to display the files for downloading:

<tr>
<td class="DetailsSublabel">File 1</td>
<td class="DetailsPage"><a href="upload/<?php echo($WADAmrf_2021_details->getColumnVal("file1")); ?>"><?php echo($WADAmrf_2021_details->getColumnVal("file1")); ?></a></td>
</tr>
<tr>
<td class="DetailsSublabel">File 2</td>
<td class="DetailsPage"><a href="upload/<?php echo($WADAmrf_2021_details->getColumnVal("file2")); ?>"><?php echo($WADAmrf_2021_details->getColumnVal("file2")); ?></a></td>
</tr>
<tr>
<td class="DetailsSublabel">File 3</td>
<td class="DetailsPage"><a href="upload/<?php echo($WADAmrf_2021_details->getColumnVal("file3")); ?>"><?php echo($WADAmrf_2021_details->getColumnVal("file3")); ?></a></td>
</tr>



Basically, I'd like the link to the file if a file exists and a form field if no file exists. Alternately, it would be nice to be able to delete an existing file and upload a new on from the update.php page.

Is this nuts? Thanks!

Sign in to reply to this post

Ray BorduinWebAssist

This would only show the row if there is a file specified in the database:

php:
<?php

if ($WADAmrf_2021_details->getColumnVal("file1")) {
?>
<tr>
    <td class="DetailsSublabel">File 1</td>
    <td class="DetailsPage"><a href="upload/<?php echo($WADAmrf_2021_details->getColumnVal("file1")); ?>"><?php echo($WADAmrf_2021_details->getColumnVal("file1")); ?></a></td>
</tr>
<?php
}
?>
Sign in to reply to this post
Did this help? Tips are appreciated...

art226587

Thanks, Ray. So, that part shows the file link if one exists, but the code below will display the form field regardless:

<div class="lineGroup"> <label for="file1" class="sublabel" > RFP File 1</label>

<?php
if ($WADAmrf_2021_details->getColumnVal("file1")) {
?>
<a href="upload/<?php echo($WADAmrf_2021_update->getColumnVal("file1")); ?>"><?php echo($WADAmrf_2021_update->getColumnVal("file1")); ?></a>
<?php
}
?>
<input name="file1" type="file" id="file1" size="30" tabindex="17" title="Please enter a value.">
</div>




How would I make this an either/or that only shows one or the other?

Sign in to reply to this post

Ray BorduinWebAssist

php:
<div class="lineGroup"> <label for="file1" class="sublabel" > RFP File 1</label>


    <?php
    
if ($WADAmrf_2021_details->getColumnVal("file1")) {
    
?>
    <a href="upload/<?php echo($WADAmrf_2021_update->getColumnVal("file1")); ?>"><?php echo($WADAmrf_2021_update->getColumnVal("file1")); ?></a>
    <?php
    
} else {
    
?>
    <input name="file1" type="file" id="file1" size="30" tabindex="17" title="Please enter a value.">
    <?php
    
}
    
?>
</div>
Sign in to reply to this post
Did this help? Tips are appreciated...

art226587

That worked great! Last question: Is there a way to allow the user to delete an existing file? It doesn't necessarily need to delete it from the file system as well. I just want a way for them to upload a newer version of the existing file if desired. This could be a multi-step process, like checking a "Delete" checkbox next to the file, clicking Submit and then updating the file again to upload a new one.

Sign in to reply to this post

Ray BorduinWebAssist

Yes. You can have an upload option on an update page. You can use whatever process you want. A checkbox would work, or just have the input field and let them know that if they specify a new file it will be replaced.

Sign in to reply to this post
Did this help? Tips are appreciated...

art226587

Ah, I see. So, if I pass a new value to that field, it will simply replace what's in the db. And just display a new upload field via a link or button with an onClick and some CSS. The "delete" part is not as clear. I think I can wrap my head around using js to pass a value to a hidden form field, but I don't know enough php/SQL to know how to empty from the db. Any pointers?

Sign in to reply to this post

Ray BorduinWebAssist

I think a checkbox to delete is probably the easiest option. Then you can check if the box was checked and clear out the field if it was with a simple IF statement. If you create the page and attach it to a reply, then I could show you where to make the change for deleting. Make sure you have everything else working before posting the file.

Sign in to reply to this post
Did this help? Tips are appreciated...

art226587

Thanks, file attached!

Sign in to reply to this post

Ray BorduinWebAssist

You can add the checkbox and then change the DefaultFileName values to clear out the value if the checkbox is checked. So, for example, line 46 might become:

'DefaultFileName' => "".(isset($_POST["deleteCheck1"])?"":$WADAmrf_2021_update->getColumnVal("file1",false)) ."",

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...