Page 1 of 1
form value from one page to another (w/o reloading)
Posted: Sat May 22, 2004 3:03 pm
by Shyft
Ok, so what I'm trying to do is to have a form which the user fills out. On this form, there is a button for the user to upload an image of themselves to accompany their information in the rest of the form. When they click this upload button, it pops up a small window through which they select their image and then upload it. This all works fine. Now, however, I want to return the uploaded file name to the original form (in a field or hidden field preferrably) without disturbing the information that the user has already entered. I need to do it this way, so that the name will then be put into a MySQL database along with the rest of the information. I would put it directly into the database, but the "insert" command hasn't been run yet with the rest of the info.
Let me know if there is any code you need posted. I dunno if it would help even, because right now it's really sloppy while I try to figure out what I'm doing.
Oh yeah, and I know some PHP and MySQL but no javascript. I would be willing to figure it out though.
Posted: Sat May 22, 2004 3:44 pm
by Weirdan
Why not just make 2page form? On the first page user fills required info and submits it to second page, which registers user and gives him ability to provide optional information about himself, such as his picture.... no need for popups and js.
Posted: Sat May 22, 2004 7:53 pm
by Shyft
I guess I could, but I want to figure out how to do this.
I found this, though I don't know how to use it:
Code: Select all
window.opener.formname.fieldname.value = ??????????
Any help?
Posted: Sat May 22, 2004 8:39 pm
by feyd
yeah, you could potentially use opener Shyft. Use that to set a value in the form, and use something similar to call a javascript function, or better yet, reload/submit the page, so that php can rebuild the page with better, nicer formatting for the image. Using the reload/submit method allows you to do any additional post processing on the file, that, for whatever reason may have been not possible with the upload popup.
basically how this will all work is you form pops the upload window, the popup is processed by a php script that kicks out a new page that sets whatever variables you need set in the original form. Set the action of the original form to "reload" the page, such that it repopulates most or all of the fields with the existing data, but adds the newly uploaded image, and finally close the popup.
The no reload way is very similar, but instead of the setting the action, you can call a function which takes the (on server) path to the uploaded file. This function loads the image and "adjusts" an existing image on the page to the new dimensions and source of the uploaded file.
Fairly simple either way.. a little more complicated with the reload, but probably looks better, unless you design the page fairly well to begin with.
I would definitely suggest processing the uploaded file into a probably smaller version, since someone could upload a huge file...

Posted: Sun May 23, 2004 3:38 am
by Shyft
I think I didn't explain it completely. I'm actually trying to get it to return just the name of the file, rather than actually displaying the image at that point. I do see what you are saying though...I'll see if it works. Thanks!
But uh...how might I use that script above? I don't know which ones are supposed to be changed in the string =/ I've only occasionally used javascript. I guess that should be my next thing to learn, huh?
Posted: Sun May 23, 2004 3:50 am
by feyd
Code: Select all
window.opener.<your form name here>.<hidden filename field>.value = '<?= $_FILESї'popupFileFieldnameHere']ї'tmp_name'] ?>';
$_FILES[..]['tmp_name'] contains the temporary name of the uploaded file, if it succeeded.
Unless you are having your upload script process the image and/or move it to a final location, you'll need to pass the tmp_name.. Otherwise, pass 'name', I think it was.