ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Unset data item

emmexx 22 Nov, 2017
In CFV<6 it was possible to remove a variable from the $form->data array by using unset.
I tried the same in CFV6 to no avali:

$this->data['myfield'] = "foo";  // this works

unset($this->data['myfield']);  // not working

I created a simple test form and I'm not sure what is happening. The setup:

a form with a textbox (myfield) and a submit button.

In the submit event I put a php action and a debugger.

If I put the 1st line of the above code in the php action the result is:

Array
(
    [option] => com_chronoforms6
    [cont] => manager
    [chronoform] => myform
    [event] => submit
    [myfield] => foo
    [button] => 
    [_ga] => GA1.2.561620972.1461746531
    [cookiesDirective] => 1
    [300gp] => R393630445
...

If I put both lines the result is:

Array
(
    [option] => com_chronoforms6
    [cont] => manager
    [chronoform] => fmyform
    [event] => submit
    [myfield] => a value
    [button] => 
    [_ga] => GA1.2.561620972.1461746531
    [cookiesDirective] => 1
    [300gp] => R393630445
...

Anyway what I want to accomplish is this: How can I edit uploaded files in a form?

I edit a form and don't want the file upload field to be updated when it is not changed.

Thank you
maxx
emmexx 24 Nov, 2017
In order to manage the editing process of uploaded files I don't understand the way CF builds the html code.

If the ghost value is set for the file field, when loading a record the ghost input element value is set to the file name.
But when i submit, this value is not submitted because the ghost value input is before the file field input. And if I don't select a file, the submit event receives an array with an empty value.

So the ghost value is not useful.

Or, as ussual, I'm missing something.

maxx
emmexx 24 Nov, 2017
In order to manage the editing process of uploaded files I don't understand the way CF builds the html code.

The "problem" affects file fields used in a repeater.

My setup:

- repeater
- file field in the repeater with Multi file select property set to No
- file field name property: myfile[{var:area_repeater5.key}]

I put a debugger in the submit event before the upload file action and one after it.

Before I get:
[myfile] => Array
        (
            [0] => 
        )
After:
[myfile] => Array
        (
            [0] => 
        )

If I use a file field outside a repeater and without [] in the name I get a different behaviour:
Before :
[myfile] => 
After:
[myfile] => afilename

Is there something wrong in my setup?

maxx
Max_admin 29 Nov, 2017
Answer
2 Likes
Hi maxx,

I edit a form and don't want the file upload field to be updated when it is not changed.
You can use a PHP action, with a code similar to below:
$new_data = $this->data;
if(empty($this->data["file"])){
unset($new_data["file"]);
}
$this->set("new", $new_data);

Then use {var:new} as the data provider of the "save data" action instead of {data:}.

Best regards
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com