close ad
 
Important WebAssist Announcement
open ad
View Menu

Web development tutorial

Customize error messages for upload form fields

Tutorial created by Ray Borduin, WebAssist

Categories: Data Bridge, Dreamweaver, PHP

rating

When adding upload functionality to your website, you may want to display messages that alert your visitors to uploading issues, should any occur. Digital File Pro includes built-in error messages that display when an upload is attempted. In this tutorial, you will learn how to modify these messages for each specific error.

arrow downWhat do you need to start?

  1. Dreamweaver CS4 or higher.
  2. Site defined in Dreamweaver - Watch video tutorial: Setting up a site in Dreamweaver.
  3. Data Bridge (alternately, Digital File Pro) installed and activated in Dreamweaver.
  4. PHP page containing digital file upload capability. For assistance, view this tutorial: Apply file upload or download.

arrow downAdd error messages

Digital File Pro displays error messages that are useful whether you wish to provide user friendly alerts after uploads fail or to show error messages for debugging your upload functionality.

  1. Open the PHP page that contains your Digital File Pro upload behavior.

  2. Open the Bindings panel from Window > Bindings.

  3. Locate the binding that relates to your upload behavior, Upload Files.


  4. In this example, the FileField name was named uploadFile when the form was previously applied to the page.


  5. Expand this entry to reveal the various bindings that are available.


    Digital File Pro includes a number of bindings that you can add to your page in this location. This document focuses on the Error Message option.

  6. Click and drag the Error Message binding to a location on your page that you would like the error message to display.


  7. Once inserted, a snippet of PHP will be added to your page.

arrow downCustomize error message binding

Depending on the error that occurs, the binding that you have added to your page will display an error message. Each error message can be customized by modifying the code. In addition, each error message has its own number that needs locating in order to create the custom code.

Locate the error codes:

  1. From the Dreamweaver Files panel, in the webassist folder, expand the file manipulation folder, and double-click to open helperphp.php.


  2. In the helperphp.php file, scroll down to locate the following line of code.


  3. From this list, locate the code for the error message you want to customize. In this example, we are going to show customizing the code that will display if the upload was successful (code = 1).

All possible error messages are displayed in this list and represented by a one or two digit number. For example, if no file was uploaded, the code is 0.


Customize the error messages:

  1. Return to your PHP page.

  2. Select the PHP binding that you added to your page previously.

  3. Choose the Split button to enter Design and Code view.


  4. In Code view, notice the following line of code.

    <?php echo $WA_DFP_UploadStatus["WA_UploadResult1"]["errorMessage"]; ?>

  5. In this line of code, replace echo with if (. Change errorMessage to statusCode as shown in the following line of code.

    <?php if ($WA_DFP_UploadStatus["WA_UploadResult1"]["statusCode"]; ?>


  6. Replace ; ?> with == 1) { ?>Upload successful!<?php } ?> as shown in the following line of code.

    <?php if ($WA_DFP_UploadStatus["WA_UploadResult1"]["statusCode"] == 1) { ?>Upload successful!
    <?php } ?>

  7. Your final code for this error message should appear as follows.


Now whenever a file is uploaded successfully, Upload successful! will display on your page.

If your form action takes you to another page, you won't be able to preview the upload success message. If your form uses action="" and you successfully upload a file, you will be able to see the success message.

Now, using the concept in this tutorial, and referring to the error codes listed in the helperphp.php file, you can create your own custom error messages for each type of error.

arrow downReviews and comments

Comments will be sent to the author of this tutorial and may not be answered immediately. For general help from WebAssist, please visit technical support.

Sign in to add comments
rating

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.