Hi,
I have a problem with using form data in a Custom field. Here's the lay of the land:
- The app is a materials catalog
- I have a table 'DBMAT_materiaal' in the same DB as Joomla with all the articles.
- I made a Connection with a Frontend-list in CCv5 using that table; modelname is 'mat'
- The field 'omschrijving' is linked to CFv5 form 'materiaal-edit'
- Created CCv5 form 'materiaal-edit' with fields that have fieldname and field-id 'mat[fieldname]'
- Linked the form save action back to the CCv5 connection
Form works fine, able to edit and save data.
So far, so good.
I have one field in the form called 'mat[afbeelding]'. In that field is the filename of an image of the article in question.
The image is stored in the images/materiaal/ folder
If the above mentioned field is filled, i want to show the image in the form. To do that is created a custom field in the form with this code:
But somehow this is not working. The no-image-small.png image is shown. Also, if i remove the if..then..else clause and just put the first echo line in, there is a broken image icon shown. Looking at the source of the rendered page i can see that the field content is not read, so the img tag ends with ...images/materiaal/.jpg which ofcourse is not a correct name.
I also tried to change
Does anyone have any ideas?
Kind regard,
Ronald de Wit
I have a problem with using form data in a Custom field. Here's the lay of the land:
- The app is a materials catalog
- I have a table 'DBMAT_materiaal' in the same DB as Joomla with all the articles.
- I made a Connection with a Frontend-list in CCv5 using that table; modelname is 'mat'
- The field 'omschrijving' is linked to CFv5 form 'materiaal-edit'
- Created CCv5 form 'materiaal-edit' with fields that have fieldname and field-id 'mat[fieldname]'
- Linked the form save action back to the CCv5 connection
Form works fine, able to edit and save data.
So far, so good.
I have one field in the form called 'mat[afbeelding]'. In that field is the filename of an image of the article in question.
The image is stored in the images/materiaal/ folder
If the above mentioned field is filled, i want to show the image in the form. To do that is created a custom field in the form with this code:
<?php
if ( isset($form->data['afbeelding']) && $form->data['afbeelding'] ) {
echo "<img src='".JURI::root()."images/materiaal/".$form->data['afbeelding'].".jpg' style='max-width:200px' />";
} else {
echo "<img src='".JURI::root()."images/materiaal/no_image_small.png' style='max-width:200px' />";
}
?>
But somehow this is not working. The no-image-small.png image is shown. Also, if i remove the if..then..else clause and just put the first echo line in, there is a broken image icon shown. Looking at the source of the rendered page i can see that the field content is not read, so the img tag ends with ...images/materiaal/.jpg which ofcourse is not a correct name.
I also tried to change
$form->data['afbeelding']
to $form->data['mat[afbeelding]']
but to no avail.
Does anyone have any ideas?
Kind regard,
Ronald de Wit
Hi Ronald,
I think that you need $form->data['mat']['afbeelding'] and I would simplify the syntax a little by using
Bob
[[>> later : added the missing . <<]]
I think that you need $form->data['mat']['afbeelding'] and I would simplify the syntax a little by using
<?php
if ( !empty($form->data['mat']['afbeelding']) ) {
$image = $form->data['mat']['afbeelding'].'.jpg';
} else {
$image = 'no_image_small.png';
}
$url = JURI::root().'images/materiaal/'.$image;
echo "<img src='{$url}' style='max-width:200px' />";
?>
Bob
[[>> later : added the missing . <<]]
Hi Bob,
That did the trick! It works fine now!
(Apart from a dot you forgot in your code between the ] and '.jpg' that is 😉 )
Thanks for your help! Coffee is on it's way!
Ronald
That did the trick! It works fine now!
(Apart from a dot you forgot in your code between the ] and '.jpg' that is 😉 )
Thanks for your help! Coffee is on it's way!
Ronald
This topic is locked and no more replies can be posted.