did display the correct value!The problem occurs when I tried to pass the value (e.g. "$form->data['Record']['ImagePath']") to src attribute value in img, by usingdata['Record']['ImagePath']; ?>" alt="image" />The src value is missing always so I didn't see any images loaded.I also tried other methods, such as using JavaScript to get value from PHP and dynamically set the src value for img tag, but it is not working either.Does anybody have idea of how to achieve this? I really appreciate any suggestions!!!Thank you all in advance!"> Load image from database in ChronoForm - Forums

Forums

Load image from database in ChronoForm

flyeminent 30 Jun, 2011
Dear GreyHead,
ChronoForm is an amazing and non-dispensable component for Joomla!
But I can't figure out how to load image from database into a Chronoform. Suppose I have a ChronoForm called "edit", which will load a row record from database table and populate the values into respective form fields. I have "DB loader" and (above) "Show Html" actions. I also set "Load Use Model ID" (e.g. Model ID is "Record") to "Yes" so that I have more control on the record data. There seems no "Image" element so I drag and use a custom element in the form. To make sure I can get the row record, I temporarily added "Custom Code" action into the form events panel, just between "DB Loader" and "Show Html", and
<?php echo $form->data['Record']['ImagePath']; ?>

did display the correct value!
The problem occurs when I tried to pass the value (e.g. "$form->data['Record']['ImagePath']") to src attribute value in img, by using
<img src="<?php echo $form->data['Record']['ImagePath']; ?>" alt="image" />

The src value is missing always so I didn't see any images loaded.
I also tried other methods, such as using JavaScript to get value from PHP and dynamically set the src value for img tag, but it is not working either.
Does anybody have idea of how to achieve this? I really appreciate any suggestions!!!
Thank you all in advance!
GreyHead 30 Jun, 2011
Hi flyeminent,

For some historic reason ChronoForms doesn't save the root part of the path. Please try
<img src="<?php echo JPATH_SITE.$form->data['Record']['ImagePath']; ?>" alt="image" />
or possibly
<img src="<?php echo JPATH_SITE.DS.$form->data['Record']['ImagePath']; ?>" alt="image" />

Bob
flyeminent 30 Jun, 2011
Thanks a lot GreyHead for your quick reply,
I will try the code tonight.
Cheers!
flyeminent 30 Jun, 2011
The "Custom Element" (<img> in this case) cannot access the record value. This means "<?php echo $form->data['Record']['ImagePath']; ?> in <img> returns nothing. So the image still cannot display properly.
GreyHead 01 Jul, 2011
Hi flyeminent ,

I'm confused, I thought you posted earlier that <?php echo $form->data['Record']['ImagePath']; ?> did display the correct value?

What value does it display?

Bob
flyeminent 01 Jul, 2011
OK, Let me rephrase the question a little bit.
I insert a "Custom Code" action right after "DB Record Loader", and set "Load Under Model ID" (let's say Model ID is "Record") to "YES" in "DB Record Loader" setting dialog. In the "Custom Code", I put <?php echo $form->data['Record']['ImagePath']; ?>, it did display the value at the frontend.
Now, I drag a "Custom Element" into the form "Preview" panel, and put it just above submit button. And in the "Custom Element" setting dialog, I put <img src="<?php echo $form->data['Record']['ImagePath']; ?>" />(To configure the "Custom Element" as an image element). At the frontend, I didn't see the picture, because the value of src is missing.
My hypothesis is that the "Custom Element" could not access the data record value, or may be need to be configured in a special way.
Is this clearer to you?
Sorry for any misunderstanding, and thank you very much for your patience.
GreyHead 02 Jul, 2011
Hi flyeminent,

I ran a test using the jos_users table and this seems to work OK.

In the OnLoad event I have a DB Load Record action before the Show HTML action. This is loading a user record with a Model ID of 'user' (I used &uid=42 in the URL to call the record).

In the Preview pane I have a Custom Element with
<?php
echo $form->data['user']['name'];
?>
{user.username}

Both data items display when I view the form in the browser - I get Super Useradmin

Bob
flyeminent 03 Jul, 2011
:lol: Yes, I should use {Record.ImagePath} instead of php echo. It is working fine now.
Please take a "Tiger" beer originated from Singapore! Cheers! :mrgreen:
This topic is locked and no more replies can be posted.