Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Playing around with a custom validator that will take the path of an image, get the height and width dimensions and save those values to the 2 extra editable fields within the same template.

I am getting the dimensions but could use little assistance with getting the values to the form to save, if even possible.

Editable's in template:

Code: Select all
<cms:editable name='testimage' label='Test image' type='image' order='1' validator='getImgStats' />
<cms:editable name='imgwidth' label='img width' type='text' order='2' />
<cms:editable name='imgheight' label='img width' type='text' order='3' />


In kfunctions.php:

Code: Select all
function getImgStats($field) {
   $image = trim($field->get_data());
   try {
      list($width, $height) = getimagesize($image);
      // save width and height into editables imgheight and imgwidth
      $field->page->_fields['imgheight'] = $height;
      $field->page->_fields['imgwidth'] = $width;
   } catch (Exception $e) {

   }
}


Thanks.
Please try using the following modification of your code instead -
Code: Select all
function getImgStats($field) {
    global $Config;
    $domain_prefix = $Config['k_append_url'] . $Config['UserFilesPath'] . 'image/';

    $image = trim( $field->get_data() );
    if( strpos($image, $domain_prefix)===0 ){ // process image only if local
        $image = substr( $image, strlen($domain_prefix) );
        if( $image ){
            $image = $Config['UserFilesAbsolutePath'] . 'image/' . $image;
            try{
                list( $width, $height ) = getimagesize( $image );

                // save width and height into editables imgheight and imgwidth
                $field->page->_fields['imgheight']->store_posted_changes( $height );
                $field->page->_fields['imgwidth']->store_posted_changes( $width );
            }catch( Exception $e ){

            }
        }
    }
}

Hope this helps.
Worked first try, ty!!
3 posts Page 1 of 1