Jump to content

Hook: Populate field value and don't save on error


Susticle
 Share

Recommended Posts

Hi,

I wrote a little module which determines the value for an read-only inputfield depending on two other required text fields. If the necessary value cannot be found, saving should be prohibited but the entered values should stay in there.

I used the hook "ProcessPageEdit::processInput" as described here and almost everything works fine. But there is one thing: The values are saved even if I detected an error. Is there a way to prevent this? I tried the hook "saveReady" but then the given values are lost in case of errors.

Thanks!

Link to comment
Share on other sites

11 hours ago, Susticle said:

If the necessary value cannot be found, saving should be prohibited but the entered values should stay in there.

That would be difficult to do as it goes against the way ProcessPageEdit works normally - when PPE loads, the values shown in the inputfields are the values stored in the database. So it also raises the question of even if you could do it (maybe save the $input->post data to $session and then hook the inputfield render to load custom content to the inputs) whether it would be a good idea given that it goes against what PW editors will be used to.

You might be better to disable the save button with Javascript if the required fields are not filled out. Note also that for text fields there is a setting to use the HTML5 required attribute which has the effect of preventing a page save when the required field is not filled out. With either of these approaches though you should consider how you will handle an attempted save from a PPE tab other than Content (e.g. an attempted save from the Settings tab).

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

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
 Share

  • Recently Browsing   0 members

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