Forums

topic Show link to file only if it has been uploaded - Still Issues for me

amheng5 05 Feb, 2019
Following instructions under url topic I have the following code instructions:<?php
if
(file_exists(JPATH_SITE.'/components/com_chronoforms6/chronoforms/uploads/' . $row['{var:name_list.row.Model.fieldname}'])
AND !empty($row['{var:Model.fieldname}']))
{
echo "Yes file";
} else {
echo "no file";
}
?>

But, I'm still getting "no file" on files that do exist. Where am I going wrong?
healyhatman 05 Feb, 2019
You can't use shortcodes in PHP.
$this->get("name_list.row.Model.fieldname");
amheng5 06 Feb, 2019
Since I am not a PHP programmer, would you mind letting me know where to place this in my code listed earlier:
healyhatman 06 Feb, 2019
Where is this PHP code, where are you getting $row from? Is this in Chronoforms, or Chronoconnectivity?
amheng5 06 Feb, 2019
I tried to duplicate the code example in the url reference above.I'm sorry this is so confusing to me.
healyhatman 06 Feb, 2019
OK no wonder it's not working. Again what are you trying to do exactly?
amheng5 06 Feb, 2019
I have a cf6 form to upload photo image. I want to use cc6 to view the data submitted with the form and have a link on the photo column to link to photo to allow viewing the image in another image (which may be larger than the one appearing in the cc6 table list view. But if the photo field is empty I want the photo column to show "no Photo"; right now is a missing icon.

Here's the page I'm working on
https://seekingadoptees.alanaheng.com/families-seeking-adoptees-report.html

here's my code (the link works for now) but I want "no Photo" to appear if no photo is uploaded.

<a href="root/components/com_chronoforms6/chronoforms/uploads/{var:table_view_list.Model.photo_upload}" target="_blank"><img src="root/components/com_chronoforms6/chronoforms/uploads/{var:table_view_list.row.Model.photo_upload}" /></a>

Here's the code use to try to accomplish my goal using HTML view:

<?php
if (file_exists(JPATH_SITE.'/components/com_chronoforms/uploads/'.$row['Model_photo_upload']))
{
echo "<a href='".JURI::root()."components/com_chronoforms/uploads/{$row['photo_upload']}' >Photo</a>";
}
if (empty($photo_upload))
{ echo "no Photo";}
?>

Hope this makes sense.
healyhatman 06 Feb, 2019
OK use a switch (under logic) instead. In the column view in your table setup, use
columnname:{fn:switch}

For the switch data source use
{var.empty:table_view_name.row.model.field}
And in the switch put
true:No Photo
false: <a href="{path:}/{var:table_view_name.row.model.field}">blahblah</a>

If that doesn't work properly, use
if (file_exists(JPATH_SITE.'/components/com_chronoforms/uploads/'.$this->get('table_view_name.row.model.field')) {
echo "<a href='" . JURI::root() . "components/com_chronoforms/uploads/" . $this->get('table_view_name.row.model.field') . "' >Photo</a>";
}
else
echo "No Photo";
amheng5 06 Feb, 2019
Ok I'll give it go on your suggestions. and I'll let you know how it goes. Thanks
healyhatman 06 Feb, 2019
Replace table_view_name with the name of your table view, replace model with your data read model, and field with the name of your field. Leave 'row' as is.
amheng5 07 Feb, 2019
Answer
Yahoo! It works with this in the fn.switch content:true:No Photo
false: <a href="my root path/components/com_chronoforms6/chronoforms/uploads/{var:table_list_name.row.Model.upload field name}" target="_blank"><img src="my root path/components/com_chronoforms6/chronoforms/uploads/{var:table_list_name.row.Model.upload field name}" /></a>
Here's test site to show in action:
https://seekingadoptees.alanaheng.com/test-view-report.html/


I added code to show my image.

Thank YOU healyhatman.
healyhatman 07 Feb, 2019
You're welcome. Please select the relevant post as "Answer" and don't forget I don't work for ChronoEngine but I DO take donations.
This topic is locked and no more replies can be posted.