help with File upload within nested forms
Moderator: General Moderators
help with File upload within nested forms
Hi,
I have a large registration form - within the form i'd like to allow the user to upload images and pdf's, i know how to do an upload however, i'd like the user to be able to make this upload before they submit the form, however when i use something like this
<form enctype="multipart/form-data" action="upload.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
within my form, as soon as you hit the "Send File" it try's to submit the form that it is nested inside of......any ideas how i can combat this issue?
Also i'd like the send file button to send the file to a php function not a php page so i can avoid redirecting the user.
thanks in advance
Greg
gregFolk is online now Reply With Quote
I have a large registration form - within the form i'd like to allow the user to upload images and pdf's, i know how to do an upload however, i'd like the user to be able to make this upload before they submit the form, however when i use something like this
<form enctype="multipart/form-data" action="upload.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
within my form, as soon as you hit the "Send File" it try's to submit the form that it is nested inside of......any ideas how i can combat this issue?
Also i'd like the send file button to send the file to a php function not a php page so i can avoid redirecting the user.
thanks in advance
Greg
gregFolk is online now Reply With Quote
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: help with File upload within nested forms
In order to accomplish this you could submit the entire form and base the "send file" execution on the "send file" button i.e.
Also, don't set an "action" in the form's parameters. Using this method, you'd need to call your validation file before the form.
Code: Select all
if(isset($_POST['submitSendFile']))Re: help with File upload within nested forms
Thanks for your response.....could you elaborate further as i don't really understand what you mean?
I have more than one "submit" button on the page, the one for the upload "send File" and then the one for the registration form "Register" and i need the user to be able to click both....sendFile - to do the upload and then Register - to complete registration.
do i put the upload php inside the
does this go on the same page as the form?
thanks again
Greg
I have more than one "submit" button on the page, the one for the upload "send File" and then the one for the registration form "Register" and i need the user to be able to click both....sendFile - to do the upload and then Register - to complete registration.
do i put the upload php inside the
Code: Select all
if(isset($_POST['submitSendFile']))
{
//upload stuff here?
}thanks again
Greg
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: help with File upload within nested forms
Why don't you upload file when user click "register" button?
Re: help with File upload within nested forms
I'm using a 3rd party pre built form (http://www.interspire.com/ - the product is called "email marketer") and this deals with the data after the registration is done and puts it inside a database etc. The problem however is that it doesn't deal with uploaded files so what i'm trying to do is upload some files first to a server then put the url of these files into the registration form and then submit the form, so then i can find the image that relates to the user without it directly being in the database.
thanks
Greg
thanks
Greg
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: help with File upload within nested forms
I see. What if they don't end up registering but files have been uploaded?
Re: help with File upload within nested forms
That's actually a good point i hadn't thought of that........I guess i'd have to run some sort of clean-up.
I did look into making the submit button post all the info to another page which did the upload and filled out a hidden form and then post onto the pre written page however then form contains checkboxes with the naming convention like this
And i can't work out how to deal with these variable names - which i assume are arrays...? Also I can't see how you hide a checkbox?
thanks
Greg
I did look into making the submit button post all the info to another page which did the upload and filled out a hidden form and then post onto the pre written page however then form contains checkboxes with the naming convention like this
Code: Select all
<td>Do you have any special skills or experience? - Please check or add any more relevant skills:</td>
<td><label for="CustomFields[34_2]_acting"><input type="checkbox" id="CustomFields[34_2]_acting" name="CustomFields[34][]" value="acting">acting</label><br/>
<label for="CustomFields[34_2]_singing"><input type="checkbox" id="CustomFields[34_2]_singing" name="CustomFields[34][]" value="singing">singing</label>
thanks
Greg
Re: help with File upload within nested forms
Nested forms are not a part of the HTML specs. Every submit button inside a form will submit the entire form, disregarding nesting.
You could achieve the effect you ask for using javascript.
You could achieve the effect you ask for using javascript.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: help with File upload within nested forms
To be honest, you really need some intervention before the form is sent off to the thrid party.
You can simply have the files uploaded but then you don't know if they have registered - which in my mind poses as a problem.
The third party must provide a callback. If so you could use this to upload the files.
You can simply have the files uploaded but then you don't know if they have registered - which in my mind poses as a problem.
The third party must provide a callback. If so you could use this to upload the files.
Re: help with File upload within nested forms
I can't really make any sense of their files....it's a bit to advanced in the php department for me. I'll up[load the file and if you fancy taking a look at it to tell me if it has this 'callback' thing then that would be great - but i do realise this is above and beyond standard forum usage!aceconcepts wrote:The third party must provide a callback. If so you could use this to upload the files.
Also pytrin - how would this be done with javascript....
I was thinking to run the php functions i wouldn't necessarily need a submit button i was hoping to just use input type="button" which would trigger a php function...?pytrin wrote:Nested forms are not a part of the HTML specs. Every submit button inside a form will submit the entire form, disregarding nesting.
You could achieve the effect you ask for using javascript.
thanks for your help
Greg
- Attachments
-
- form.php.zip
- (4.93 KiB) Not downloaded yet