Calling request class from controller causes blank screens.

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
mikeritteronline
Registered User
Posts: 3
Joined: Fri Apr 20, 2018 9:54 pm

Calling request class from controller causes blank screens.

Post by mikeritteronline » Sun Apr 22, 2018 5:38 pm

EDIT: Moving the important bit to the top here.


I have tried using the request class via service container and calling a new instance

When I call the class with either method my whole app breaks and i get just a blank screen



I am supporting a legacy project from 3.1.x

I am building my first extension

I know my way around symfony-based frameworks

I have worked through the area 51 guide on extensions

I have worked through the symfony 2.3 book

I have worked through the 3.1 dev wiki on area 51

I have built a working form in a template

here's my controller

Code: Select all

<?php

namespace vertu\fldirectentry\controller;

use phpbb\request\request;
use vertu\fldirectentry\Task;

class main{

	protected $config;
	protected $helper;
	protected $template;
	protected $user;

	public function __construct(\phpbb\config\config $config, \phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\user $user) {
		$this->config = $config;
		$this->helper = $helper;
		$this->template = $template;
		$this->user = $user;
	}

	public function index() {
		return $this->helper->render('fldirectentry_create.html', "FL Direct Entry");
	}

	public function show() {
		return $this->helper->render('fldirectentry_show.html', "FL Task");
	}

	public function store() {
		// 1. get request
		return $this->getRequest();
		// 2. validate request data
		// 3. sanitize request data
		// 4. create task
		$task = new Task();
		$task->setClientName( $client_name );
		$task->setActionWhenComplete( $action_when_complete );
		$task->setClientStrategy( $client_strategy );
		$task->setContentType( $content_type );
		$task->setDistributionType( $distribution_type );
		$task->setPublishLink( $publish_link );
		// 5. store task
		// 6. show result
		return redirect('/fl/directentry/show');
	}

	public function getRequest(){
                // process the post request vars
	}
}
In the last method I'm trying to process the request variables

I have tried

Code: Select all

$_POST
which successfully throws the error screen saying to use the request class or the deprecated

Code: Select all

request_var
I have successfully run

Code: Select all

die(print_r($_POST));
to view my form data
Last edited by mikeritteronline on Wed Apr 25, 2018 10:11 am, edited 2 times in total.

User avatar
canonknipser
Registered User
Posts: 1598
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: How do I get the values from a form I created in a template?

Post by canonknipser » Sun Apr 22, 2018 7:39 pm

Try to use the Extension development tool, which gives you a collection of samples how to write a extension including form input/output using phpBB-templates instead of native symphony forms. In phpBB, symphony is most time far in the background
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB

mikeritteronline
Registered User
Posts: 3
Joined: Fri Apr 20, 2018 9:54 pm

Re: How do I get the values from a form I created in a template?

Post by mikeritteronline » Sun Apr 22, 2018 9:14 pm

Thanks.

I went back and created an extension with everything with that extension.

The form there is in MCP and built as a module, not as an extension.

mikeritteronline
Registered User
Posts: 3
Joined: Fri Apr 20, 2018 9:54 pm

Re: How do I get the values from a form I created in a template?

Post by mikeritteronline » Sun Apr 22, 2018 10:20 pm

canonknipser wrote:
Sun Apr 22, 2018 7:39 pm
Try to use the Extension development tool, which gives you a collection of samples how to write a extension including form input/output using phpBB-templates instead of native symphony forms. In phpBB, symphony is most time far in the background
Oh man!

This extension created the forms in ACP and MCP, but with the acme\demo namespace.

I was hoping to find what to use for "form name". :roll:

User avatar
GanstaZ
Registered User
Posts: 412
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: Calling request class from controller causes blank screens.

Post by GanstaZ » Sun Apr 22, 2018 11:13 pm

All the files you created with skeleton tool is part of your extension. Example of form in acp module:

Code: Select all

        add_form_key('acme_demo_settings');

        if ($request->is_set_post('submit'))
        {
            if (!check_form_key('acme_demo_settings'))
            {
                 trigger_error('FORM_INVALID');
            }

            $config->set('acme_demo_goodbye', $request->variable('acme_demo_goodbye', 0));
            trigger_error($language->lang('ACP_DEMO_SETTING_SAVED') . adm_back_link($this->u_action));
        }
In controller everything is pretty much the same, but differs with service injections via constructor and you have free hands with method naming and so on.
"When answer lies in the question,.. question becomes redundant!"

User avatar
3Di
Registered User
Posts: 12895
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Calling request class from controller causes blank screens.

Post by 3Di » Mon Apr 23, 2018 1:06 am

mikeritteronline wrote:
Sun Apr 22, 2018 10:20 pm
I was hoping to find what to use for "form name".
You need another tool for that and many more, which is not yet finished. :geek:
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Calling request class from controller causes blank screens.

Post by posey » Mon Apr 23, 2018 9:18 am

The request_var is also outdated / deprecated. What you want to be using is the request class.
- https://github.com/phpbb/phpbb/blob/mas ... equest.php
- https://area51.phpbb.com/docs/code/3.1. ... quest.html

You have the html:

Code: Select all

<form id="something" method="post" action="{{ SOME_U_ACTION }}">
    <input type="text" name="variable1">
    <input type="submit" name="submit" value="{{ lang('SUBMIT') }}">
</form>
Then in the php-side of things (usually the controller), you request the form input's names. (eg. 'variable1' and 'submit').

Code: Select all

if ($submit = $this->request->is_set_post('submit'))
{
    $variable1 = $this->request->variable('variable1', '', true);

    // Process the variable further ..
}
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests