FORMfields, the premiere web framework
Login
Support Home | Knowledge Base | Documentation | Forums | Contact Us
Info
FORMfields & FORMgen :: Generated Forms

Variable Number of UploadFields

(1238 views. Last Updated: 2007-09-11 11:58 AM)

Here is an example of how to create a form with a variable amount of UploadFields. In this example we will create a form where the user can submit up to 5 uploads. Note: the following example will not work properly with the "On Submit Display Confirmation Screen Option."

1. Use FORMgen to create a form and add the fields:
- UploadField: Field Name: upload1
- UploadField: Field Name: upload2, Required: Not Required
- UploadField: Field Name: upload3, Required: Not Required
- UploadField: Field Name: upload4, Required: Not Required
- UploadField: Field Name: upload5, Required: Not Required

2. On Step 5 of FORMgen, select "Insert Form Data Into Database". This step is only required if you want the form data to be stored in a database.

3. Edit your form using a text editor like notepad and replace:
$ffForm = new FfForm();
$ffForm->addField(new UploadField("upload1", "Upload 1", FORM_FIELD_REQUIRED, 2000000));
$ffForm->addField(new UploadField("upload2", "Upload 2", FORM_FIELD_NOT_REQUIRED, 2000000));
$ffForm->addField(new UploadField("upload3", "Upload 3", FORM_FIELD_NOT_REQUIRED, 2000000));
$ffForm->addField(new UploadField("upload4", "Upload 4", FORM_FIELD_NOT_REQUIRED, 2000000));
$ffForm->addField(new UploadField("upload5", "Upload 5", FORM_FIELD_NOT_REQUIRED, 2000000));
$ffForm->addField(new SubmitField("ff_submit", "Submit"));
$ffForm->addField(new SubmitField("ff_clear", "Clear"));
$ffForm->addField(new SubmitField("ff_cancel", "Cancel"));
with:
$ffForm = new FfForm();
$ffForm->addField(new UploadField("upload1", "Upload 1", FORM_FIELD_REQUIRED, 2000000));

if (!FormField::getOrNull("ff_clear", $_REQUEST)) {
    if (FormField::getOrNull("upload1_uploaded_file", $_REQUEST) || FormField::getOrNull("upload1_upload_now", $_REQUEST)) {
        $ffForm->addField(new UploadField("upload2", "Upload 2", FORM_FIELD_NOT_REQUIRED, 2000000));
    }
    if (FormField::getOrNull("upload2_uploaded_file", $_REQUEST) || FormField::getOrNull("upload2_upload_now", $_REQUEST)) {
        $ffForm->addField(new UploadField("upload3", "Upload 3", FORM_FIELD_NOT_REQUIRED, 2000000));
    }
    if (FormField::getOrNull("upload3_uploaded_file", $_REQUEST) || FormField::getOrNull("upload3_upload_now", $_REQUEST)) {
        $ffForm->addField(new UploadField("upload4", "Upload 4", FORM_FIELD_NOT_REQUIRED, 2000000));
    }
    if (FormField::getOrNull("upload4_uploaded_file", $_REQUEST) || FormField::getOrNull("upload4_upload_now", $_REQUEST)) {
        $ffForm->addField(new UploadField("upload5", "Upload 5", FORM_FIELD_NOT_REQUIRED, 2000000));
    }
}

$ffForm->addField(new SubmitField("ff_submit", "Submit"));
$ffForm->addField(new SubmitField("ff_clear", "Clear"));
$ffForm->addField(new SubmitField("ff_cancel", "Cancel"));

Note: You can also substitute the above UploadFields with UploadWebImageFields and UploadWebImageViewerFields.
Info
Support | Earn Money
Copyright © 2005-2019 Brain Book Software LLC.
Built with FORMfields, the premiere web framework.