Susticle Posted September 10, 2018 Share Posted September 10, 2018 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! Link to comment Share on other sites More sharing options...
Tom. Posted September 10, 2018 Share Posted September 10, 2018 Not too sure what doGeocoding function is doing but have you tried hooking before Pages::save? Also check out this https://modules.processwire.com/modules/fieldtype-map-marker/ which does what you are trying to accomplish. 2 Link to comment Share on other sites More sharing options...
Susticle Posted September 11, 2018 Author Share Posted September 11, 2018 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. :-) Link to comment Share on other sites More sharing options...
Soma Posted September 11, 2018 Share Posted September 11, 2018 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; } }); 1 1 Link to comment Share on other sites More sharing options...
Susticle Posted September 11, 2018 Author Share Posted September 11, 2018 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! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now