We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    Is there a nice tidy way to set the formit hooks in a class?

    I have a snippet [GetArtistData]:
    /**
     *
     * snippet.GetArtistData.php
     *
     * Created using: JetBrains PhpStorm
     * User: Sean Kimball [email protected]
     * BigBlock Studios http://www.bigblockstudios.ca
     * http://github.com/BigBlockStudios
     * Date: 29/04/12, 6:36 PM
     *
     */
    
    $classfile = dirname($modx->getOption('core_path')).'/core/components/extdata/controllers/extdata.class.php';
    
    if (file_exists($classfile)) {
        $output = include_once $classfile;
    } else {
        $modx->setLogTarget('ECHO');
        $modx->log(modX::LOG_LEVEL_ERROR,'class not found at: '.$file);
    }
    
    $scriptproperties = array('query'=>'false',);
    
    if(class_exists('ExtraData') != true)
    {
       $ExtraData = new ExtData($modx,$scriptproperties);
    }
    
    
    $output = $ExtraData->getData($scriptproperties);
    
    $hook->setValues(array(
    	'title'=>$output['title'],
    	'bio'=>$output['bio'],
    	'banner'=>$output['banner'],
    	'manager'=>$output['manager'],
    	'FaceBook'=>$output['FaceBook'],
    	'YouTube'=>$output['YouTube'],
    	'Twitter'=>$output['Twitter'],
    	'MySpace'=>$output['MySpace'],
    ));
    
    
    
    return true;
    
    



    calling this function within the ExtData class:
        // get data from the extra data tables...
        public function getData($scriptproperties){
    
            $output = '';
    
            $uid = $this->modx->getLoginUserID();
    
            // look for existing artist record
            $artistId = $uid;
    
            $records = $this->modx->getObject	('ArtistAttributes', array('userkey'=>$artistId));
    	   
    	   $social = json_decode($records->get('social'),true);
    
            $output = array(
    			'userkey'=>$records->get('userkey'),
    			'title'=>$records->get('title'),
    			'banner'=>$records->get('banner'),
    			'bio'=>$records->get('bio'),
    			'manager'=>$records->get('manager'),
    			'social'=>$social,
    			'FaceBook'=>$social['FaceBook'],
    			'Twitter'=>$social['Twitter'],
    			'YouTube'=>$social['YouTube'],
    			'MySpace'=>$social['MySpace'],	
            );
    	   
            return $output;
    	   
        }
    




    seems to me like I am overdoing it here, is there a nice tidy way to return the output array as 'hooks' to formit?

    Also, slightly related, this is used as a prehook to populate the form, and as a hook to repopulate the form after submission, it works perfect when the page is visited initially, but after the form is submitted the form will remain blank after the page refreshes.... I am placing it after the update hook & the update hook always returns true... thoughts?

    
    [[!FormIt?
        &preHooks=`GetArtistData`
        &hooks=`UpdateArtist,GetArtistData`
        &successMessage=`Updated!`
        &validate=`title:required, bio:required`
        &segment=`attributes`
    ]]
    






      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 4172
      • 5,888 Posts
      you can send the $hook - object to your function:

      $ExtraData->getData($scriptproperties,$hook);


      and reference it there:

      public function getData($scriptproperties, & $hook)
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!