Forums

Problem with displaying an Image in DB in Form $form->$form_details problem

StuckInForms 11 Apr, 2015
The problem I am having is displaying a pre-existing image (of the logged in user) in the form.

I am following the instructions in this post on how to show the image and give users the ability to change it or delete the image (see this article https://www.chronoengine.com/faqs/60-cfv4/cfv4-working-with-the-database/2666-how-can-i-edit-the-record-for-an-image.html)

I’ve almost gotten it working but am getting the error:

Undefined property.... $form_details
[attachment=0]2015-04-10_chronoforms error.jpg[/attachment]

Note the 2nd echo is returning the "no image found" image from the directory... the issue, according to my expert php developer friend:

"The code that is inserted is trying to access information
from the $form variable. That variable exits and contains
data, but I don't see anything for $form->form_details there.

There is no value for the '$form->form_details->name' that
you are using, because there is no '$form->form_details'
at this point, even though I see multiple examples of it
on their forums. I don't know if that is only present after
a POST or not."


The code being using is:

<?php
if ( isset($form->data['image']) && $form->data['image'] ) {
  echo "<img src='".JURI::root()."images/sitestuff/ez_user_profile_images/{$form->form_details->name}/{$form->data['image']}' style='max-width:175px' />";
} else {
  echo "<img src='".JURI::root()."images/sitestuff/ez_user_profile_images/{$form->form_details->name}/no_image.jpg' style='max-width:175px' />";
}
?>


Can anyone figure out what the issue we're having is and how to fix it in Chronoforms V5?
Help is much appreciated.
"Stuck"
GreyHead 15 Apr, 2015
Hi StuckinForms,

The code to get the name of the current form changed between CFv4 and v5. In v5 it is now $form->form['Form']['title']

But you can just add the folder name if you know it- replace some_folder in this snippet
<?php
if ( !empty($form->data['image']) ) {
  echo "<img src='".JURI::root()."images/sitestuff/ez_user_profile_images/some_folder/{$form->data['image']}' style='max-width:175px' />";
} else {
  echo "<img src='".JURI::root()."images/sitestuff/ez_user_profile_images/some_folder/no_image.jpg' style='max-width:175px' />";
}
?>

Or, if the images are in the 'form name' folder and you want the portable version please try
<?php
if ( !empty($form->data['image']) ) {
  echo "<img src='".JURI::root()."images/sitestuff/ez_user_profile_images/{$form->form['Form']['title']}/{$form->data['image']}' style='max-width:175px' />";
} else {
  echo "<img src='".JURI::root()."images/sitestuff/ez_user_profile_images/{$form->form['Form']['title']}/no_image.jpg' style='max-width:175px' />";
}
?>

Bob
StuckInForms 16 Apr, 2015
HI Bob,

That was the answer, the form works perfectly now. Many thanks for the help.

I had to figure out I need to put my form element name in replacing 'image' - I didn't sleep in a Holiday Inn Express, or know much about php object programming so this Jurassic squirrel had to sort of figure it out...

There's a cup of coffee coming your way. Your help is invaluable.

Best regards,
"un Stuck"
This topic is locked and no more replies can be posted.