PHP get Field value of another field

PHP get Field value of another field

Andreas S.Andreas S. Posts: 208Questions: 74Answers: 4
edited May 2017 in Editor

I have to upload one file in a little bit complex directory structure. To build the correct directory for the upload I need two other fields of the submitted Form. I have no idea how can I read this two field in the customized upload field in the server-side script.

        Field::inst( 'events_list.list_deadline ' )
            ->validator( 'Validate::dateFormat', array(
                'empty' => false,
                'format' => $update
            ))
            ->getFormatter( 'Format::date_sql_to_format', $update)
            ->setFormatter( 'Format::date_format_to_sql', $update),
        Field::inst( 'events_list.list_event_type' )
            ->options('events_types', 'type_id', 'type_name_en')
            ->validator( 'Validate::dbValues' ),
        Field::inst( 'events_list.list_i_pdf' )
            ->setFormatter( 'Format::ifEmpty', null )
            ->upload(
                Upload::inst( function($file, $id){
    
    // here I want to check the subdirectory
                
                    })
                    ->db( 'files', 'file_id', array(
                            'file_name' => Upload::DB_FILE_NAME,
                            'file_size' => Upload::DB_FILE_SIZE,
                            'file_web_path' => Upload::DB_WEB_PATH,
                            'file_system_path' => Upload::DB_SYSTEM_PATH,
                            'file_extension' => Upload::DB_EXTN
                ))
                ->validator( function ( $file ) {
                    return$file['size'] >= 500000 ?
                        "Files must be smaller than 500K" :
                        null;
                } )
                ->allowedExtensions( array( 'pdf', 'docx' ), "" )
        ),

for example I need the events_list.list_deadline and events_list.list_event_type submitted fields to check the directory structure. If the check failed I must create it otherwise the upload starts. I tried it with the $_POST["events_list.list_deadline"] but I did not get any value. Have you a idea what I do here wrong?

Andreas

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I have no idea how can I read this two field in the customized upload field in the server-side script.

    There is no built in option to do that I'm afraid. The file upload is async from the rest of the form, so it would be entirely valid for the user to upload the file before filling in the other fields.

    However, what you could do is use the ajaxData option of the upload file type - give it a custom function that will read the data from the form fields and include it in the upload so you could use it from $_POST[].

    Allan

This discussion has been closed.