Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sessions variables and repeated form fields

Status
Not open for further replies.

scousethemoose

Programmer
Jul 14, 2002
69
AU
Heres my problem, I think it can be solved using sessions variables but I'm not sure exactly how to implement it.

I have a page in which a user can upload a file, initially only one upload field is visible, a user can increase the number of upload fields using a button which reloads the page with the additional fields.

This is done by repeating the html code for the form fields using a while loop.

Now to my problem... How can I set it up so that if a user decides that they want an additional field the information they have entered alreading isnt lost on the page reload?

Is there any alternatives to a page reload, maybe a client side script to increase the fields with out a reload.

Its probably already been covered somewhere but I cant seem to find it.

Can anyone help or at least point me in the right direction?

 
If you are to use PHP to solve this problem, then the form must be reloaded. As PHP runs only on the server, there is no other way to invoke the script.

I recommend that you place multiple submit buttons on the form, each with its own value and label. Your script can then, using the submitted values, react to differing user clicks.

The drawback of this method is that if the user selects a file to be uploaded before deciding to add form inputs, the selected file will be uploaded. This will slow the reaction of the script.

If you want to use client-side scripting, I recommend that you ask the question in the appropriate forum.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Wait.

It is possible to have the form be submitted yet have no selected files uploaded.

Place the submit buttons that will add inputs be in their own forms.


Also, keep in mind that the script which handles the uploads must be able to determine how many files are uploaded. Are you aware of the ability of PHP to treat file input names of the form 'name="foo[]"' as a single array of inputs in $_POST?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi I think my explaination may have been a little poor...

I have implemented the file uploading already and the adding of additional fields. There is one upload button with uploads all the values from the multiple file input fields..

All I want to know really is how to implement session variables correctly so that if a user decides to add an addtional file upload field done using a page reload with out the form being submitted, the values already entered remain.
 
If there is a value already in place in a file input, then that value will be submitted. T....

Nevermind.....

You can't do it. You can't prepopulate a filename of an input of type "file". This is a security feature that was added to most browsers many years ago.

You might be able to do something with client-side scripting.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks, I thought I'd have to do some client side scripting. Oh well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top