Buy Now
Sign in

Unset data item

emmexx , November 22 2017
Answered
E
emmexx
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
E
emmexx
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
E
emmexx
[quote="emmexx"
  • In order to manage the editing process of uploaded files I don't understand the way CF builds the html code.[/quote]

    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
    admin
    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
    If your main question got answered then please mark the answer using the button!​
    ​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!