Jump to content

Extension talk:Page Forms/Developers' documentation

Add topic
From mediawiki.org

Instruction causes error

[edit]

This instruction just leads to Fatal error: Call to a member function setInputTypeHook() on a non-object in --DaSch (talk) 13:24, 23 July 2012 (UTC)Reply

That's strange - what version of SF are you using? And are you calling this code after including SF? You can always look at the Semantic Forms Inputs extension to see how to do it - it essentially uses this same approach. Yaron Koren (talk) 13:52, 23 July 2012 (UTC)Reply
I use latest from git. I also tried to build it like it is done in Semantic Forms Inputs with $sfgFormPrinter->registerInputType that didn't work. Is there maybe a possibility to check somewhere which input-types are registred? --DaSch (talk) 13:56, 23 July 2012 (UTC)Reply
Hi - there are ways to check, but it doesn't seem relevant here, because the issue here is just that the code doesn't know what $sfgFormPrinter is. This is a silly question, but are you definitely calling "global $sfgFormPrinter" beforehand? Yaron Koren (talk) 14:01, 23 July 2012 (UTC)Reply
global $sfgFormPrinter;
$sfgFormPrinter->setInputTypeHook('html5', 'sfHtml5', array());

function sfHtml5($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;

if ( array_key_exists( 'class', $other_args ) ) {
$className .= ' ' . $other_args['class'];
}
$input_id = "input_$sfgFieldNum";
$disabled_text = ( $is_disabled ) ? 'disabled' : '';
$html5input=$field_args['html5'];
$html = <<<END
<input id="$input_id" name="{$input_name}[value]" type="$html5input" class="$className" tabindex="$sfgTabIndex" $checked_str $disabled_text/>
END;
return $html;
}

--DaSch (talk) 14:09, 23 July 2012 (UTC)Reply

Okay, I figured it out. I was not aware, that the form is checked against the template and kills non matching or not existing fields. --DaSch (talk) 14:18, 23 July 2012 (UTC)Reply
Okay - I don't see how that would lead to the first error you described, but I'm glad you figured it out. Yaron Koren (talk) 14:26, 23 July 2012 (UTC)Reply

Documentation

[edit]

Your example is nearly useless. I cant find out where to put the code and what the connection between the input definition in the form (input type) and the function hook is. Can you wirte down a basic ready to use example? This would help mutch more then anything else. The map extension is to complicated.

Hi - maybe it would help to look at the code for the Semantic Forms Inputs extension? That one does seem more straightforward than the Semantic Maps code. Yaron Koren (talk) 15:17, 21 February 2013 (UTC)Reply

Is the documentation out of date?

[edit]

I tried to follow the documentation and got the following error: Error from line 1626 of C:\xampp\htdocs\testnew\extensions\PageForms\includes\PF_FormPrinter.php: Class 'myclassname::myfunction' not found. I think the argument should be a subclass of PFFormInput and not a function name as mentioned in the examnple.Nischayn22 (talk) 19:41, 10 March 2018 (UTC)Reply

Oops, sorry about that - this has been out of date for a long time. I just updated this explanation; hopefully it's correct (and useful) now. Yaron Koren (talk) 14:04, 11 March 2018 (UTC)Reply
Thanks. I could get past this error but my custom input wasn't working. I get the following warning which seems to be the cause of it: Parameter 1 to ClassName::onFormPrinterSetup() expected to be a reference, value given in Hooks.php on line 186. Nischayn22 (talk) 14:24, 11 March 2018 (UTC)Reply

Changing

		Hooks::run( 'PageForms::FormPrinterSetup', array( $this ) );

to

		Hooks::run( 'PageForms::FormPrinterSetup', array( &$this ) );

Seems to fix this for me. Nischayn22 (talk) 15:05, 11 March 2018 (UTC)Reply

Yes, I had that same thought while creating the documentation. Thanks for confirming the problem, and the fix. I just checked in a similar fix. Yaron Koren (talk) 00:23, 12 March 2018 (UTC)Reply