File Field/Upload not working

FenFire 31 Mar, 2015
Hi,
I created a User registration via Chronoforms and it works great. But I have a problem with the picture file field in the adequate "Edit profile"-form.
1. I "DB Read" the user details in a Model called Data. So the filename is in Data[avatar]. It's there, i tested it with a text box, but it's not filled in the File Field. Can that be changed?
2. If I choose a file it's not uploaded AND Data[avatar] doesn't seem to be in the array (debugger doesn't list this field); of course, then also nothing is saved in the avatar column. If I used this snippet you (Max) mentioned somewhere in the forum:
<?php
echo'<div>$_FILES: '.print_r($_FILES, true).'</div>';
?>

I get this:
$_FILES: Array ( [Data] => Array ( [name] => Array ( [avatar] => Passsbild_klein.jpg ) [type] => Array ( [avatar] => image/jpeg ) [tmp_name] => Array ( [avatar] => /mnt/shared/tmp/php1haGfD ) [error] => Array ( [avatar] => 0 ) [size] => Array ( [avatar] => 39068 ) ) ) 


My setting in Files Upload action:
Files Config: Data[avatar]:jpg-png
Upload Path: components/com_arrange2drive/media/users
Array fields is empty

What does that mean? It's looks like a path or rights problem. But I copied the "Edit" form from the "Registration" form and there it works without problems. I tried to set all relevant directory properties to 777, without effect.

Can you help me out?
Thanks in advance.

Christian
GreyHead 01 Apr, 2015
Hi Christian,

Making images editable is not straightforward. The entry required in the File Upload action is a path on the user's computer and you don't know what that is. Please see this FAQ

Bob
FenFire 01 Apr, 2015
Hey Bob,
that's a great FAQ - I immediately inserted it; the only problem is that I don't know how to put in model field Data[avatar] instead of 'image'. I tried things like $form->data['Data[avatar]'] or $form->Data['avatar'] or $form->data['Data["avatar"]'] - nothing worked.

This also doesn't solve my primary problem. The field field is not in the Data model and therefore not saved. I checked the spelling more than twice, it seems correct. What might be the problem here?

Christian
GreyHead 01 Apr, 2015
Hi Christian,

It would be $form->data['Data']['avatar'] - the standard PHP array format.

If it isn't being saved then my best guess is that you have the DB Save action before the Upload Files action so there is nothing to save.

Bob
FenFire 01 Apr, 2015
Ok, the data array works now. I got confused with data and the model, and also just realized that the model in this case is part of array itself.

Now, this is my On submit Setup. The dbsave-Action definitiely comes after Files Upload:
[attachment=0]avatar_problem.jpg[/attachment]

Could it be that the Files Config is wrong? I put "Data[avatar]:jpg-png" in there.

Christian
FenFire 01 Apr, 2015
And here's also the debugger info concerning the data array:

[attachment=0]avatar_problem2.jpg[/attachment]
GreyHead 01 Apr, 2015
Hi fenfire,

I'm confused - there is no Data[avatar] showing in the Debugger output. I think it should be there - though perhaps with no value?

Bob
FenFire 01 Apr, 2015
Hi Bob,
yes, that's actually the problem. My Designer looks like this:
[attachment=0]avatar_problem3.jpg[/attachment]

It's visible and enabled, of course.
If you wanna try for yourself (the debugger is still active), I can PN or Email you a testaccout - or you register.

Thanks in advance
Christian
GreyHead 01 Apr, 2015
Hi Fenfire,

When I look at the form the file upload is disabled - that's why it doesn’t show in the form results.

Bob
FenFire 01 Apr, 2015
Sorry, but I had to change it again after a time because the site is online and used (at least a bit).
I enabled the file field again and also the debugger. Please check if possible - you will get the results I mentioned.

Christian
GreyHead 01 Apr, 2015
Hi Christian,

Thank you - that's working correctly and I can see that the file data is being submitted:
------WebKitFormBoundarykpn86sn7kiTEikBl
Content-Disposition: form-data; name="Data[avatar]"; filename="test_image.jpg"
Content-Type: image/jpeg


But I notice now that the form Method is set to POST, please try changing that to FILE in the HTML (Render Form) action.

Bob

PS If you need to have the form live then make a Copy with the icon in the Form Manager Toolbar - then you can develop on the copy without affecting the live version until you are ready to replace it.
FenFire 01 Apr, 2015
Hey Bob,

in my HTML Render action there's file selected. I compared it to the (working) registration form, it's also file there.
[attachment=0]avatar_problem4.jpg[/attachment]
So I supposed there must be another reason? Or can that selection be overwritten? The other settings, beginning with Sign required labels are Yes, Yes, No, Yes, No.

Christian

P.S. I normally develop locally, but it didn't think there would be a big difficulty.
FenFire 01 Apr, 2015
Edit: I tried to change the HTML render method to post and back to file, with no effect. The form method seems to stay "post".
GreyHead 04 Apr, 2015
Hi FenFire,

I'm baffled by this at the moment. I tested locally and changing the HTML (Render Form) setting correctly changes the setting in the <form> tag. I think that is the cause of the problem but don't see why it isn't changing for you.

Just a thought . . . do you have site caching on? That might prevent the change taking place immediately.

Bob
FenFire 08 Apr, 2015
Hi Bob,
I'm back from holidays, but still stuck here.
I have site caching on, but I'm trying at this for quite a while now. I deleted Joomla and Chronoforms cache, also tried in a different browser, but the form method shown in the source code is still "post" although in the HTML Render Action it is set to "file".
Any more advices/hints?

Christian
FenFire 10 Apr, 2015
Okay, just one more updated.
1) I tried to delete the HTML Render action, save the forms, and put the HTML Render action back in. No effect.
2) I took a look at the working registration form with upload. The form method here is also set to "file", but in the source code output in frontend I can read "post". It works, though. In fact all my forms are set to file, but all of them show "post" in frontend. So maybe this is not the problem??
GreyHead 15 Apr, 2015
Hi FenFire,

I've been looking at this but don't have any new ideas. Usually it 'just works'.

Please try adding a Custom Code action in the On Submit event with this code in it:
<?php
echo'<div>$_FILES: '.print_r($_FILES, true).'</div>';
?>
That should just dump the PHP files info - you can check to see if the file is being uploaded at all ad/or if any errors show.

Bob
FenFire 15 Apr, 2015
Hi Bob,

I already did this in my first post. Here it is. The directory shown here - might that bei the problem? (The one I entered is: components/com_arrange2drive/media/users)
$_FILES: Array ( 
  [Data] => Array ( 
    [name] => Array ( 
      [avatar] => Mera2014-3klein.jpg 
    ) 
    [type] => Array ( 
      [avatar] => image/jpeg 
    )
    [tmp_name] => Array (
      [avatar] => /mnt/shared/tmp/phpssaa9C
    )
    [error] => Array (
      [avatar] => 0
    ) 
    [size] => Array ( 
      [avatar] => 73570
    ) 
  )
)
Christian
GreyHead 17 Apr, 2015
Answer
Hi Fenfire,

Sorry, I didn't look back far enough :-(

The folder isn't a problem - what happens is that PHP uploads the file to a temporary folder and then ChronoForms moves it from there to the final folder location.

There is something odd here though I would expect the $_files array to have values like [Data][avatar][name] and instead it has [Data][name][avatar].

If you change the upload name so that it is just avatar instead of Data[avatar] does that then work?

Bob
FenFire 17 Apr, 2015
That did it!!!
I only have to hand the value of 'avatar' over to 'Data.avatar' via PHP Custom Code after the Files Upload action.

Thanks a lot!

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