Page 1 of 1

help with File upload within nested forms

Posted: Wed Nov 12, 2008 4:51 am
by gregFolk
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

Re: help with File upload within nested forms

Posted: Wed Nov 12, 2008 5:00 am
by aceconcepts
In order to accomplish this you could submit the entire form and base the "send file" execution on the "send file" button i.e.

Code: Select all

if(isset($_POST['submitSendFile']))
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.

Re: help with File upload within nested forms

Posted: Wed Nov 12, 2008 5:08 am
by gregFolk
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

Code: Select all

  if(isset($_POST['submitSendFile']))
{
//upload stuff here?
}
does this go on the same page as the form?

thanks again

Greg

Re: help with File upload within nested forms

Posted: Wed Nov 12, 2008 5:18 am
by aceconcepts
Why don't you upload file when user click "register" button?

Re: help with File upload within nested forms

Posted: Wed Nov 12, 2008 5:23 am
by gregFolk
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

Re: help with File upload within nested forms

Posted: Wed Nov 12, 2008 5:30 am
by aceconcepts
I see. What if they don't end up registering but files have been uploaded?

Re: help with File upload within nested forms

Posted: Wed Nov 12, 2008 5:35 am
by gregFolk
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

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>
 
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

Re: help with File upload within nested forms

Posted: Wed Nov 12, 2008 5:38 am
by Eran
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.

Re: help with File upload within nested forms

Posted: Wed Nov 12, 2008 5:41 am
by aceconcepts
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.

Re: help with File upload within nested forms

Posted: Wed Nov 12, 2008 6:07 am
by gregFolk
aceconcepts wrote:The third party must provide a callback. If so you could use this to upload the files.
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!

Also pytrin - how would this be done with javascript....
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.
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...?

thanks for your help

Greg