<p>I'm trying to access the value of an asset field in a backend entry form from my plugins own field type.</p>

<p>At the moment it's looking like the following:</p>

<pre><code>public function prepValue($value)
{
    $filename = "path/to/csv";

    if( ($handle = fopen( $filename, "r")) !== FALSE) {
        $rowCounter = 0;
        while (($rowData = fgetcsv($handle, 0, ";")) !== FALSE) {
            if( 0 === $rowCounter) {
                $headerRecord = $rowData;
            } else {
                foreach( $rowData as $key =&gt; $val) {
                    $value[ $rowCounter - 1][ $headerRecord[ $key] ] = $val;  
                }
            }
            $rowCounter++;
        }
        fclose($handle);
    }
    return $value;
}
</code></pre>

<p>All of the csv values are mapped to a table column of the same field type:</p>

<pre><code>public function getInputHtml($name, $value)
{   
    $id = 'test';
    $cols = array(
        'col_1' =&gt; array(
            'heading' =&gt; 'Col 1',
            'type'    =&gt; 'singleline',
        ),
        'col_2'   =&gt; array(
            'heading' =&gt; 'Col 2',
            'type'    =&gt; 'singleline'
        ),
        'col_3'   =&gt; array(
            'heading' =&gt; 'Col 3',
            'type'    =&gt; 'number'
        ),
        'col_4'   =&gt; array(
            'heading' =&gt; 'Col 4',
            'type'    =&gt; 'number'
        ),
        'col_5'   =&gt; array(
            'heading' =&gt; 'Col 5',
            'type'    =&gt; 'singleline'
        ),
        'col_6'   =&gt; array(
            'heading' =&gt; 'Col 6',
            'type'    =&gt; 'singleline',
        ),
    );

    return craft()-&gt;templates-&gt;render('csvImport/csvimport', array(
        'name'  =&gt; $name,
        'value' =&gt; $value,
        'id'    =&gt; $id,
        'cols'  =&gt; $cols,

    ));
}
</code></pre>

<p>I would like to fill $filename dynamically with the value of an asset field in the same entry backend form. Is this possible?</p>

<p>//EDIT:</p>

<p>Ok I solved the above problem by just changing the prepValue() to the prepValueFromPost()-Function. I now am able to access every piece of data I want to through the post array.</p>

CC BY-SA 3.0
2014-11-03T19:06:33.330Z
When do you need the value? Do you need it before saving the entry or do you need it as soon as the other field's value changes?
Tyler Willingham
CC BY-SA 3.0
2014-11-04T10:39:33.503Z
It would be enough to have it when the save button is clicked. So in the "onBeforeSave" function for example (which never seems to be called for whatever reasons...).
LikeAJohny
<plugin-development><entry><custom-fieldtype>
Is it possible to access backend fields from my own field type?
# Is it possible to access backend fields from my own field type?

(Asked by: username_0 on 2014-11-03)

I'm trying to access the value of an asset field in a backend entry form from my plugins own field type.
At the moment it's looking like the following:
public function prepValue($value)
{
    $filename = "path/to/csv";

    if( ($handle = fopen( $filename, "r")) !== FALSE) {
        $rowCounter = 0;
        while (($rowData = fgetcsv($handle, 0, ";")) !== FALSE) {
            if( 0 === $rowCounter) {
                $headerRecord = $rowData;
            } else {
                foreach( $rowData as $key => $val) {
                    $value[ $rowCounter - 1][ $headerRecord[ $key] ] = $val;  
                }
            }
            $rowCounter++;
        }
        fclose($handle);
    }
    return $value;
}

All of the csv values are mapped to a table column of the same field type:
public function getInputHtml($name, $value)
{   
    $id = 'test';
    $cols = array(
        'col_1' => array(
            'heading' => 'Col 1',
            'type'    => 'singleline',
        ),
        'col_2'   => array(
            'heading' => 'Col 2',
            'type'    => 'singleline'
        ),
        'col_3'   => array(
            'heading' => 'Col 3',
            'type'    => 'number'
        ),
        'col_4'   => array(
            'heading' => 'Col 4',
            'type'    => 'number'
        ),
        'col_5'   => array(
            'heading' => 'Col 5',
            'type'    => 'singleline'
        ),
        'col_6'   => array(
            'heading' => 'Col 6',
            'type'    => 'singleline',
        ),
    );

    return craft()->templates->render('csvImport/csvimport', array(
        'name'  => $name,
        'value' => $value,
        'id'    => $id,
        'cols'  => $cols,

    ));
}

I would like to fill $filename dynamically with the value of an asset field in the same entry backend form. Is this possible?
//EDIT:
Ok I solved the above problem by just changing the prepValue() to the prepValueFromPost()-Function. I now am able to access every piece of data I want to through the post array.

**Tags:** plugin-development, entry, custom-fieldtype

> **Comments:**
> **username_1**: When do you need the value? Do you need it before saving the entry or do you need it as soon as the other field's value changes?  
> **username_0**: It would be enough to have it when the save button is clicked. So in the "onBeforeSave" function for example (which never seems to be called for whatever reasons...).  

---

## 0 answers

