Jump to content

User generated selections


carlg

Recommended Posts

I'm not sure of the appropriate subject line for this feature, but hopefully I'm close.  I'll try to describe what I'm trying to do.  The most common place you see this is on web based file uploads so I'll use it as my example.

 

Let's say I want to allow my user to upload files so there is a text box where they enter the file name.  The user is allowed to upload as many files as he wants with 1 push of the submit button.

 

Upon the loading of the form, there will be 5 textboxes for file upload, but if the user wants to upload more than 5 files, there is a link that is clicked and I think via ajax or javascript another textbox will be added.  The user can do this for as many files he wants to upload.  This is what it looks like to the user, but then when the form is submitted how are these variables referenced?

 

So how is this setup in the main form and how are the variables referenced after form submission?

 

If anyone can point me to a good web tutorial on this type of thing I would appreciate it.

 

Thanks

 

Carl

 

 

Link to comment
Share on other sites

First off a file upload field is not a text box - it is a file input that will include a browse button.

 

Anyway, you can simply create your form with however many file input fields as you want. Then, using javascript, provide a method for the user to add more input fields. The key to this is to name the input fields as an array. Then you can reference the fields on the receiving page as an array

<input type="file" name="files[]" 

Link to comment
Share on other sites

"First off a file upload field is not a text box - it is a file input that will include a browse button."

I knew this already, thanks.  File upload is the most common place you see this technique used on the web.

 

In my application, there will be groupings of 3 items (2 dropdowns and 1 text box).

 

So I guess I would handle this in a similar fashion?

 

Thanks again.

 

 

 

Link to comment
Share on other sites

In my application, there will be groupings of 3 items (2 dropdowns and 1 text box).

 

Not quite sure what you are trying to say there. Are you saying that each upload will consist of several fields: one for the actual file upload and additional fields to describe the upload?

 

If so, then all the fields should be defined as arrays. Example

File 1: <input type="file" name="files[]" />
Type: <select name="filetype[]"><option>Avatar</option><option></option>thumb</select>
Name: <input type="text" name="file_name" />

File 2: <input type="file" name="files[]" />
Type: <select name="filetype[]"><option>Avatar</option><option></option>thumb</select>
Name: <input type="text" name="file_name" />

//etc...

 

Then, on the processing page, to access the fields for the first image you would use:

$_POST['files'][0], $_POST['file_type'][0], $_POST['file_name'][0]

 

For the second image:

$_POST['files'][1], $_POST['file_type'][1], $_POST['file_name'][1]

 

etc.

Link to comment
Share on other sites

Yes, very similar to that, thanks.

 

Besides I'm not doing file uploads (I just used file uploads as an example since it is a common place to see this technique used)

 

My application will have student name, grade point average, and major.

 

The user can add as many students as he wishes;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.