Forums

Repopulate file upload - SOLVED

apptech 11 Aug, 2010
Hi,

First of all - thanks so much for chronoforms! Saved me a huge amount of coding time.

I have a question about repopulating a form. I have a membership registration form that users fill in all sorts of details including being able to upload a photo. This works great and I can see all the data. I then wanted to repopulate the form so when a user wants to modify the data they don't have to type it all in again. Again got it all working lovely except the uploaded image. I can obviously get the filename from the database and I tried (in my form html)
<?php
    $value = "";
    if ($data == 1)
    {
        $value = "value=\"" . $row->fileupload. "\"";
    }
    echo "
                <input class=\"cf_inputbox\" maxlength=\"250\" size=\"50\"  name=\"fileupload\" type=\"file\" $value/>
    ";
?>

where $data says if there is some data already stored in the DB for that user.
This didn't work and I searched the net and came back with the answer - you can't do it this way.

So my question is, any ideas how I could do this within my chronoform such that when the user submits their updated data it keeps the previous file upload if no new one is entered?

Thanks
GreyHead 11 Aug, 2010
Hi apptech,

If you are using the ChronoForms DB Connection then any columns that are *not* in the result array will be left unchanged. So you need to make sure that if there isn't a new file then the file name input is removed from the $_POST array before the data is saved.

Bob
apptech 11 Aug, 2010
Thanks for getting back so quickly - yes I am using the chronoforms db connection. I turned on debug and checked that the file upload is indeed not in the $_POST array, but because a whole new record is created in the database, as the filename field is empty (and therefore the old data is lost), the field in the database is empty. So when I recall the data the next time, I use the latest record for a particular user but of course there is not file name associated anymore. Is there something I should be changing to make it do an update not an insert into the database? Or am I approaching this in entirely the wrong way?

Form passed first SPAM check OK
Form passed the submissions limit (if enabled) OK
Form passed the Image verification (if enabled) OK
Form passed the server side validation (if enabled) OK
$_POST Array: Array ( [subject] => Modified membership registration [username] => testreg [realname] => XXXX [manufacturer] => XXXX [model] => XXXX [renappr] => on [leadhol] => on [renperm] => on [nurstel] => 123123 [techtel] => 123123 [nurperm] => on [nursemail] => XXXX [freq] => 0 [duration] => 0.00 [beds] => 3 [double] => 1 [single] => 2 [bunks] => 0 [cots] => 0 [smoke] => No [bsmoke] => No [pets] => No [bpets] => Yes [wbpets] => Hamster [lpets] => Yes [wlpets] => Cat [ball] => Nuts, fur [wall] => Nuts [swapped] => 0 [refs] => N/A [postcode] => XXXX [XXXX] => 1 [1cf1] => XXXX [chronoformname] => MembershipRegistration )
$_FILES Array: Array ( [fileupload] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) )
Form passed the plugins step (if enabled) OK
An email has been SENT successfully from (MembershipRegistrationForm)registration@XXXX.co.uk to [email]registration@XXXX.co.uk[/email]
Debug End


Some of the fields changed to protect details
apptech 11 Aug, 2010
Had a thought - if I have a hidden field called oldfileupload in which I write the filename into, then somewhere during the form submit (not sure whether to use form tag attachment or onSubmit before email or after email but thats a different question), can I cheat and add a field to the $_POST array called fileupload which will use the oldfileupload if $_FILE error is set?
GreyHead 11 Aug, 2010
Hi apptech ,

To have ChronoForms do an update you need to include the Primary Key of the record in the form as a hidden input.
<input type='hidden' name='cf_id' value='XXXX' />


Bob
apptech 11 Aug, 2010
Fantastic - all solved. Thanks ever so much.
Draw 17 Dec, 2010
Hi,

I'm facing the same problem, the upload field does not allow repopulation.
This wouldn't be an issue if indeed he would recognize that when empty he shouldn't POST the field.
I also ran the debug, and on the contrary to the previous posts even though the field was empty you can see him trying to upload. (second to last step)

I'm probably missing out on a certain setting somewhere?


Form passed first SPAM check OK
Form passed the submissions limit (if enabled) OK
Form passed the Image verification (if enabled) OK
Form passed the server side validation (if enabled) OK
$_POST Array: Array ( [Date] => 2010-12-06 [Category] => Train [button_9] => Submit [Amount] => 250.00 [Currency] => EUR [Comments] => Testje voor andere datum [Status] => Changed [cf_id] => 55 [AmountEur] => 250.00 [38d6a2463c37ca982d9a650b3e3dea8e] => 1 [1cf1] => b40a931049fb795e9c45bf6ca869b55b [chronoformname] => ChangeData )
$_FILES Array: Array ( [Photo] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) )
Upload routine started for file upload by : Photo
Form passed the plugins step (if enabled) OK
Debug End



Thanks in advance for any guidance🙂
GreyHead 17 Dec, 2010
Hi Draw,

I'm not clear that you have the same problem at all. Please will you say a bit more about what it is?

File Error 4 - is an empty input so the user isn't trying to reload here.

Bob
Draw 17 Dec, 2010
Hi Greyhead, thanks once again for the quick response.

So my question is, any ideas how I could do this within my chronoform such that when the user submits their updated data it keeps the previous file upload if no new one is entered?



This was the original question and is the same issue I'm facing.
When they try to upload a new file the record has to be updated -> This works
If they do not upload any file the previous one should remain inside the DB -> This does not work.
As you can see from the debug, even though the uploadfield is empty, he attempts to upload.
And making it a required field is not an option a fetching the existing value in the field does not seem to work (at least not with value=...)

Thanks in advance!
Draw
GreyHead 17 Dec, 2010
Hi Draw,

I'm confused, if you have the same problem then I think that the answer is the same:

So you need to make sure that if there isn't a new file then the file name input is removed from the $_POST array before the data is saved.

I believe that you can do this in the OnSubmit Before box.

Bob
Draw 18 Dec, 2010
Hi Greyhead,

Does it need to be deleted from the $_POST array or from the $_FILES array?
Because the DEBUG report seems to state that {Photo} isn't in there to begin with?

I've tried both using this code snippet,however nothing seemed to happen?
<?php 
if($_POST['Photo'] == '')
unset($_POST['Photo']);
?>


When switching $_POST for $_FILES I get a white screen filled with errors.

Thanks once again!
GreyHead 31 Dec, 2010
Hi Draw,

Sorry to be so long in getting back to this. Have you managed to solve it?

Bob
This topic is locked and no more replies can be posted.