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