jFormer DocumentationBasic Fields

File

JFormComponentFile(String id, String label[, Array optionArray])

The File field type allows users to select files from their computer to be uploaded on form submission.

Usage

Constructor

    new JFormComponentFile(String id, String label[, Array optionArray])

Sample Usage

Create a simple file component:

    $file = new JFormComponentFile('id', 'Label:');
    

Value Returned

Array, [name, type, tmp_name, error, size(in bytes)]

CSS Class

.jFormComponentFile

Component Options

These options are common to all components.

null

description

HTML | a description for the component, shows underneath the component inside a DIV with the class jFormComponenpescription.

null

instanceOptions

Array, [max(int), addButtonText(string), removeButtonText(text)] | see instanceOptions page for more information.

null

dependencyOptions

Array, [dependentOn(string), display(string), jsFunction(Javascript)[, animationOptions(array)]] | see dependencyOptions page for more information.

null

triggerFunction

Javascript | a javascript function that runs upon component change.

null

tip

HTML | a tooltip that displays whenever the component has focus. Gives any extra help or explanation a form user might need.

null

validationOptions

Array | an of validations specific to the component, see the specific component for its validations.

false

showErrorTipOnce

Boolean | this option makes the error tip only show up on the first focus on the component if it does not pass validation.

false

enterSubmits

Boolean | if true pressing enter while this component has focus submits the form, or advances to the next page.

null

style

CSS | set the style attribute for the component wrapper div.

null

initialValue

String | preset the value of the component upon form loading.

File Validation Options

NameError Message and Description
required

"Required."

The 'required' validation checks to make sure the component has a value.

                'validationOptions' => array('required'),
            

In some cases, you may wish to use 'matches' in a setting where there can be more than one instance of a section that contains both the original field and the field you want to match against. In this case, 'matches' must be assigned to an associate array that contains two keys. The first key, 'matches' receives an HTML ID (without the #) of the particular field that you wish to match a value against. The second key, 'sectionInstances' receives a boolean indicating whether or not the value you want to match against is a member of a section that can have more than one instance. For example:

                'validationOptions' => array(
                    'matches' => array(
                        'matches' => 'password',
                        'sectionInstances' => true
                    )
                ),
            
extension

"Must have the 'user defined' extension."

The 'extension' validation takes a value a determined extension and checks to make sure the file selected has that extension.

                'validationOptions' => array('extension' => 'txt'),
            
extensionType

"Incorrect file type."

The 'extensionType' validation makes sure the file selected is of the correct type, types are:

  • image: bmp, gif, jpg, png, psd, psp, thm, tif
  • document:doc, docx, log, msg, pages, rtf, txt, wpd, wps
  • audio:aac, aif, iff, m3u, mid, midi, mp3, mpa, ra, wav, wma
  • video:3g2, 3gp, asf, asx, avi, flv, mov, mp4, mpg, rm, swf, vob, wmv
  • web:asp, css, htm, html, js, jsp, php, rss, xhtml
  • custom:rather than setting a string you can set a custom array of extensions
                'validationOptions' => array('extensionType' => 'image'),
            
size

"File must be smaller then [sizelimit]kb. File is [filesize]kb."

The 'size' validation takes a integer and checks it against the file size (in kb) of the uploaded file (server side only).

                'validationOptions' => array('size' => 1024),
            
imageDimensions

if file is not am image:

"File is not a valid image file."

if image is larger than dimensions given:

"Image must be less then [width]px wide. File is [imagesize]px."

"Image must be less then [height]px tall. File is [imagesize]px."

The 'imageDimensions' validation takes an array with keys of 'width' and 'height' and checks the image size against these values.(server side only)

                'validationOptions' => array('imageDimensions' => array('width' => 800, 'height' => 600)),
            
minImageDimensions

if file is not am image:

"File is not a valid image file."

if image is smaller than dimensions given:

"Image must be more then [width]px wide. File is [imagesize]px."

"Image must be more then [height]px tall. File is [imagesize]px."

The 'minImageDimensions' validation takes an array with keys of 'width' and 'height' and checks the image size against these values.(server side only)

                'validationOptions' => array('minImageDimensions' => array('width' => 800, 'height' => 600)),
            

Next Page: Hidden

This page was last edited on April 11, 2011 at 3:14pm.

3 comments (add a comment)

LAGRANGE on 2011-07-21 06:32:58

The input file don't works with the google chrome browser !

LAGRANGE on 2011-07-21 06:34:16

The input file don't works with the google chrome browser !

zef on 2011-09-11 12:05:27

Two notes:
1.It works in Chrome and Opera. You have to set parameter
'customStyle'=>false
in Options array

2. Value returned is object. Not array!

Hope it helps somebody.