Jump to content

Recommended Posts

Posted

Hi,

here is my attempt in short. I want to hook the submitted form in custom admin module and fire a function if conditional applies.

Problem: I cannot find a working hook to check if a form has been submitted. I would like to fire the addButtonMethod function if the form "form_application" is submitted by the "hook_accept_application" button.

I know it sounds basic, but I have tried all of the following without success. Thanks a lot for the help

public function init() {
  parent::init();
  $this->addHookBefore('InputfieldForm::processInput', $this, 'addButtonsMethods');
  $this->addHookBefore('InputfieldWrapper::processInput', $this, 'addButtonsMethods');
  $this->addHookBefore('InputfieldSubmit::processInput', $this, 'addButtonsMethods');
}

public function ___execute() {
  $modules = $this->wire('modules');
  $form = $this->modules->get("InputfieldForm");
  $form->action = "./";
  $form->method = "post";
  $form->attr("id+name", "form_application");
  $btn_application_create = $this->modules->get("InputfieldSubmit");
  $btn_application_create->attr('id+name', 'hook_accept_application');
  $btn_application_create->value = "Start Student";
  $btn_application_create->addClass("ui-priority-primary button_submit");
  $form->append($btn_application_create);

  return $form->render();
}

public function addButtonsMethods($event) {
  if($this->input->post->hook_accept_application){
  	wire('session')->redirect(wire('pages')->get(123)->editUrl;
  }
}

 

 
Posted

Hi @Federico

Why just not check for input post like 

$modules = $this->wire('modules');
  $form = $this->modules->get("InputfieldForm");
  $form->action = "./";
  $form->method = "post";
  $form->attr("id+name", "form_application");
if($this->wire('input')->post->your_submit_button) {
  $btn_application_create = $this->modules->get("InputfieldSubmit");
  $btn_application_create->attr('id+name', 'hook_accept_application');
  $btn_application_create->value = "Start Student";
  $btn_application_create->addClass("ui-priority-primary button_submit");
  $form->append($btn_application_create);
}

 

Posted

Hi @Zeka

In the code above I have the POST input check, as follow:

if($this->input->post->hook_accept_application){
	wire('session')->redirect(wire('pages')->get(123)->editUrl;
}

which works. However, for a more articulated module development I am looking for a hook method to fire a function when the form named "form-application" is submitted. In other words, I am looking to wrap it into a function like the following one. Any idea?

public function addButtonsMethods($event) {
  if($this->input->post->hook_accept_application){
  	wire('session')->redirect(wire('pages')->get(123)->editUrl;
  }
}

 

Posted

Ok, then

public function ___execute()
{
	$out = '';
	$input = $this->wire('input');
	$modules = $this->wire('modules');
	$form = $this->modules->get("InputfieldForm");
	$form->action = "./";
	$form->method = "post";
	$form->attr("id+name", "form_application");
	$btn_application_create = $this->modules->get("InputfieldSubmit");
	$btn_application_create->attr('id+name', 'hook_accept_application');
	$btn_application_create->value = "Start Student";
	$btn_application_create->addClass("ui-priority-primary button_submit");
	$form->append($btn_application_create);

	if ($input->post->hook_accept_application) {
		$form->processInput($input->post);

		if ($form->getErrors()) {
			$out .= $form->render();
		} else {
			$this->addButtonsMethods();
		}
	} else {
		$out = $form->render();
	}

	return $out;
}

public function addButtonsMethods($event)
{
	wire('session')->redirect(wire('pages')->get(123)->editUrl;
}

 

  • Like 1
Posted

Thanks @Zeka and @bernhard

for some reasons the code posted by Bernard gives an error, even if starts with 

$this->wire->addHookAfter

instead of just 

$wire->addHookAfter

 maybe because the form name declaration in this method (I did not know, can you actually declare the form name in that?)

InputfieldForm(name=form-application)::processInput

 Anyway, I have solved this minor issue with the approach as per the Zeka suggestion. Thank you both

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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