I have the ghost formatting of the field to be correct, but if the file upload field is left blank it doesn't select the ghost value just the empty field on data save.
I am using J3.8.2 and CF6 latest release.
debug if I upload an image in edit form:
Array
(
[validate_fields2] => Array
(
[log] => Automatic validation enabled.
[var] => 1
)
[upload12] => Array
(
[path] => /home/domains/vol3/797/1404797/user/htdocs/webapp/uploads/agents/
[agent_image] => Array
(
[extensions] => Array
(
[0] => jpg
[1] => jpeg
[2] => png
[3] => gif
)
[saved] => 1
)
[var] => Array
(
[agent_image] => Array
(
[path] => /home/domains/vol3/797/1404797/user/htdocs/webapp/uploads/agents/20171124194920_et-finger-jack.jpg
[filename] => 20171124194920_et-finger-jack.jpg
[name] => et-finger_jack.jpg
[size] => 122720
)
)
)
[save_data4] => Array
(
[data] => Array
(
[aid] => 1
[chronoform] => edit_agent
[event] => submit
[agent_image] => 20171124194920_et-finger-jack.jpg
[name] => xxxxx
[email] => xxxxxx
[phone] => xxxxxx
[bio] => Big guy. Small smile bbbb
[button6] =>
[a2e59797cfd7e007061e0cdfe2dddcbc] => 658joab2vchn2dofbknldpvm85
[b9ef1604eaada687139b7d361fdfc189] => 49i7qj45rf8vosjv6tp3qkkm31
[joomla_user_state] => logged_in
[slider-mybgcarousel] => 0
[_ga] => GA1.2.92911649.1490033135
[_gid] => GA1.2.2126637492.1510587806
[Itemid] => 287
[option] => com_chronoforms6
[view] => form
[modified] => 2017-11-24 19:49:20
)
[_success] => Data saved successfully
[log] => Array
(
[0] => UPDATE `jos_chronoengine_chronoforms_data_add_agent` AS `Agent` SET `agent_image` = '20171124194920_et-finger-jack.jpg', `name` = 'xxxxxxxx', `email` = 'xxxx@xxxx.com', `phone` = 'xxxxx', `bio` = 'Big guy. Small smile bbbb', `modified` = '2017-11-24 19:49:20' WHERE `aid` = '1' AND `aid` = '1';
)
[var] => Array
(
[agent_image] => 20171124194920_et-finger-jack.jpg
[name] => xxxxx
[email] => xxxx@xxxx.com
[phone] => xxxxxx
[bio] => Big guy. Small smile bbbb
[modified] => 2017-11-24 19:49:20
)
)
[read_data5] => Array
(
[log] => Array
(
[0] => SELECT `Agent`.`aid` AS `Agent.aid`, `Agent`.`user_id` AS `Agent.user_id`, `Agent`.`created` AS `Agent.created`, `Agent`.`modified` AS `Agent.modified`, `Agent`.`name` AS `Agent.name`, `Agent`.`email` AS `Agent.email`, `Agent`.`phone` AS `Agent.phone`, `Agent`.`agent_image` AS `Agent.agent_image`, `Agent`.`bio` AS `Agent.bio` FROM `jos_chronoengine_chronoforms_data_add_agent` AS `Agent` WHERE `Agent`.`aid` = '1' LIMIT 100;
)
[var] => Array
(
[Agent] => Array
(
[aid] => 1
[user_id] => 0
[created] => 2017-11-09 11:46:31
[modified] => 2017-11-24 19:49:20
[name] => xxxxxx
[email] => xxxxxx@xxx.com
[phone] => xxxxxx
[agent_image] => 20171124194920_et-finger-jack.jpg
[bio] => Big guy. Small smile bbbb
)
)
)
)
debug output on submit if i leave the agent_image field blank:
Array
(
[validate_fields2] => Array
(
[log] => Automatic validation enabled.
[var] => 1
)
[upload12] => Array
(
[path] => /home/domains/vol3/797/1404797/user/htdocs/webapp/uploads/agents/
[agent_image] => Array
(
[extensions] => Array
(
[0] => jpg
[1] => jpeg
[2] => png
[3] => gif
)
[info] => File is not present.
)
[var] => Array
(
)
)
[save_data4] => Array
(
[data] => Array
(
[aid] => 1
[chronoform] => edit_agent
[event] => submit
[agent_image] =>
[name] => xxxxxxx
[email] => xxxxx@xxxxx.com
[phone] => xxxxxxx
[bio] => Big guy. Small smile bbbb
[button6] =>
[a2e59797cfd7e007061e0cdfe2dddcbc] => 658joab2vchn2dofbknldpvm85
[b9ef1604eaada687139b7d361fdfc189] => 49i7qj45rf8vosjv6tp3qkkm31
[joomla_user_state] => logged_in
[slider-mybgcarousel] => 0
[_ga] => GA1.2.92911649.1490033135
[_gid] => GA1.2.2126637492.1510587806
[Itemid] => 287
[option] => com_chronoforms6
[view] => form
[modified] => 2017-11-24 19:52:46
)
[_success] => Data saved successfully
[log] => Array
(
[0] => UPDATE `jos_chronoengine_chronoforms_data_add_agent` AS `Agent` SET `agent_image` = '', `name` = 'xxxxxx', `email` = 'xxx@xxxxx.com', `phone` = 'xxxxxx', `bio` = 'Big guy. Small smile bbbb', `modified` = '2017-11-24 19:52:46' WHERE `aid` = '1' AND `aid` = '1';
)
[var] => Array
(
[agent_image] =>
[name] => xxxxxxx
[email] => xxxxx@xxxxx.com
[phone] => xxxxxx
[bio] => Big guy. Small smile bbbb
[modified] => 2017-11-24 19:52:46
)
)
[read_data5] => Array
(
[log] => Array
(
[0] => SELECT `Agent`.`aid` AS `Agent.aid`, `Agent`.`user_id` AS `Agent.user_id`, `Agent`.`created` AS `Agent.created`, `Agent`.`modified` AS `Agent.modified`, `Agent`.`name` AS `Agent.name`, `Agent`.`email` AS `Agent.email`, `Agent`.`phone` AS `Agent.phone`, `Agent`.`agent_image` AS `Agent.agent_image`, `Agent`.`bio` AS `Agent.bio` FROM `jos_chronoengine_chronoforms_data_add_agent` AS `Agent` WHERE `Agent`.`aid` = '1' LIMIT 100;
)
[var] => Array
(
[Agent] => Array
(
[aid] => 1
[user_id] => 0
[created] => 2017-11-09 11:46:31
[modified] => 2017-11-24 19:52:46
[name] => xxxxxxx
[email] => xxxx@xxxxx.com
[phone] => xxxxxx
[agent_image] =>
[bio] => Big guy. Small smile bbbb
)
)
)
)
Some fields may not appear in the data array after the form is submitted if they did not have any selections or changes made, to
avoid this issue which has some negative side effects, there is a “Ghost” feature available for these fields, it should be enabled
by default and in most scenarios you should keep it enabled.
The ghost value is set to an empty string by default, which means that if no selection is made then send an empty string under
this field name, but you can change it to something else if you have a specific requirement.
My ghost value is there , but hidden which i believe is correct, however it doesn't override agent_image field if no file is selected to upload.
Here's the html output for the file upload field - agent_image :
<div class="field "><label for="agent_image">Change / Add Image</label>
<input type="hidden" name="agent_image" value="20171124194920_et-finger-jack.jpg" data-ghost="1">
<input name="agent_image" id="agent_image" type="file"></div>
<?php
if(!$this->data('agent_image')){
unset($this->data('agent_image'));
}
?>
But i get a blank screen , turning php errors on development i get:
Can't use method return value in write context in /.../htdocs/libraries/cegcore2/admin/extensions/chronofc/helpers/parser.php(100) : eval()'d code on line 3
The ghost value should be the way to solve this, I will try to find out what is causing it not to work, but the "unset" line should also work if you change it to:
unset($this->data['agent_image']);
Best regards
I've changed it to
<?php
if(!$this->data('agent_image')){
unset($this->data['agent_image']);
}
?>
and tried :
<?php
if(!$this->data['agent_image']){
unset($this->data['agent_image']);
}
?>
But still removes the existing image on save even if the fle upload is incorrect.
Any help appreciated
Ben
Any news on the ghost file not working, did you find out why? Still cant get it to work, everything else is working perfectly.
Thanks
Ben
Look at https://www.chronoengine.com/forums/posts/t104687/p373817#p373817 for my form it works.
p.
<?php
$img = $this->data['agent_image'];
if(!$img){$img = $this->get('read_data18.Agent.agent_image');}
echo $img;
?>