Jump to content

My own hook doesn't work


wegorz23

Recommended Posts

Hello, I created my own hook.  This hook has the task of entering the value into the database. 

My code looks like this : 

//<?php

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

class hook57 extends _HOOK_CLASS_
{
  
  /**
	 * Process create/edit form
	 *
	 * @param	array				$values	Values from form
	 * @return	void
	 */
	public function processForm( $values )
	{
          if(static::$customDatabaseId == 30) {
           $values['field_157'] = 1;
        }
           parent::processForm( $values );
        }
}

But when I add a record, I get an error : 

IPS \ Db \ Exception (1366)

Incorrect integer value: '' for column 'field_157' at row 1

Why is this happening?

Link to comment
Share on other sites

You need to make the hook extend the actual records class that it needs to work with, or else static::$customDatabaseId won't be set. So, for example, if you are working against database ID #3, then you would extend \IPS\cms\Records3.

This class is automatically created (via eval()) from applications/cms/Application.php right at the top of the file in the spl_autoload_register() definition for reference. There is a different class for each database (there is also \Comment3, Review3, Categories3, RecordsTopicSync3, CommentTopicSync3, and Fields3 with the database ID 3 example here for reference).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...