Jump to content

Backend complains about missing values after filling in hook


Recommended Posts

Posted

Hello,

I have a template with various fields to input address data. These inputs are used in a hook to do geocoding via a Google API.

Also there are two required fields, for latitude and longitude.

When I add data in the page editor of Processwire and save, my module fills these fields with data given by Google. This works quite well.

My problem is: Processwire says that required values are missing but displays the correct values in the fields. If I do a second save, everything is fine.

This is the hook I used:

public function init() {
	$this->pages->addHookBefore('ProcessPageEdit::processInput', $this, 'doGeocoding');
}

Note: I also tried "addHookAfter", no change.

So everything is fine but an error is shown. Do you have an hints? Thank you!

Posted

Thanks for your reply!

Hooking before "Pages::save" shows exactly the same behavior.

I saw the module written by @ryan but our data structure is different and I have an own library to get the coordinates. It works quite well and matches all the needs I had and have for several projects.

I would like to learn what I am doing wrong. Most likely there will be other cases I could need this knowledge about filling required fields and save without errors. :-)

Posted

Your hook doesn't tell anything about how you manipulate the data. This works just fine for me in ready.php :

$this->addHookBefore("ProcessPageEdit::processInput", function (HookEvent $event) {
    $form = $event->arguments("form");
    if($form->get("lat")) {
        $this->input->post->lat = 12;
    }
});

 

  • Like 1
  • Thanks 1
Posted
12 minutes ago, Soma said:

Your hook doesn't tell anything about how you manipulate the data.

Right. I should have been more precise there. Sorry.

I had no doubts that this way might be the problem but I was wring. I filled the input fields and thought that this should work.

Your simple answer solved my problem. Thank you very much!

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...