Forums

Ghost value

jack19 22 Jul, 2022
I can't understand what goes into the Ghost field.
If I leave it blank, the previously uploaded image is also deleted from the database. Instead it should save it (stored) in the database.

https://www.chronoengine.com/faqs/60-cfv4/cfv4-working-with-the-database/2666-how-can-i-edit-the-record-for-an-image
jack19 22 Jul, 2022
I used this value
{var:read_data4.Model1.image}
as source code I see the hidden field correctly filled,
<input type="hidden" name="Model1[image]" value="20220722103020_saveriofrancesco.jpeg" data-ghost="1" />
but when I submit the form the field is empty.

in debug the field is empty
[var] => Array
                (
                    [Nome] => Saverio
                    [Cognome] => Francesco
                    [image] => 
                )
jack19 04 Aug, 2022
How is it possible that you are unable to solve this issue/bug?
jack19 18 Aug, 2022
Help please.
GreyHead 21 Aug, 2022
Hi Gioacchino,

The Ghost field provides a default value to be returned if the form field is not completed by the user. You could try putting the existing image path in there, but it might be simpler to use custom PHP to check for an empty value and remove it from the dataset before saving - I think that is what the FAQ describes, though for an earlier version of CF.

Bob
jack19 21 Aug, 2022
Hello GreyHead,
What I indicated should work:
"
I used this value
{var:read_data4.Model1.image}
as source code I see the hidden field correctly filled,
<input type="hidden" name="Model1[image]" value="20220722103020_saveriofrancesco.jpeg" data-ghost="1" />
"
I followed several FAQs about it but I could not solve, not even with a php code that I found in the FAQ and in various posts.

Maybe the php code I found and adapted doesn't work.

I can try again but possibly what would be the value to indicate, do you have a more specific example?
I in the ghost I used this code
{var:read_data4.Model1.image}
Which in the html source correctly displays the path in the hidden field of the ghost. As you can see at the beginning of this thread.
Could you give me a php example on this issue?
Thank you for answering me.
GreyHead 25 Aug, 2022
Hi Gioacchino,

Well done, if you can please will you post the solution here to help other users.

Bob
jack19 25 Aug, 2022
Answer
Hi everyone, here is my solution.
In setup, form actions I insert a PHP Logic (PHP code without tags) (See Image)


// I have created a query to extract the data from the database
$ID=$_GET['ID'];
$db = JFactory::getDbo();
$db->setQuery("SELECT * FROM `#__YOUR_TABLE` WHERE `ID`=$ID");
$results = $db->loadObjectList();
foreach ($results as $result) {
$img = $result->image;
}
//I check if the file field is empty and if it is empty I set the $img value taken from the query
if(empty($this->data['Model']["image"])){
$this->data['Model']["image"] = $img;
}

Maybe it could have been done another way, but the only one I've been able to make work is this.
You need to login to be able to post a reply.