Juergen Posted June 19, 2015 Share Posted June 19, 2015 hello @ all, I want to find out if this is possible in PW. I have 3 fields in a template: field 1: Option fieldtype with 2 options to select (single choice). -option 1 (standard price) -option 2 (offer price) field 2: Input fieldtype decimal for the standard price value (fe 10€) - equals option 1 field 3: Input fieldtype decimal for the offer price value (fe 5€) - equals option 2 So here is the process: 1) Select if the price should be a standard price or a offer price 2) If field 2 and 3 have values in it - then delete the value of the option which is not choosen after pushing the save button. Example: I choose standard price (option 1) Field 2 (standardprice) will be filled with the value 10 € by me Field 3 (offerprice) contains the value 5 € from an earlier time as this was an offer. After saving the article the value of 5€ from field 3 should be deleted because I have choosen option 1 (standard price). Therefore the offerprice is no longer needed and should be deleted. I hope it is clear what I mean. SO IS IT POSSIBLE TO DELETE THE VALUE OF ONE FIELD DEPENDING ON THE VALUE OF ANOTHER FIELD AFTER PRESSING THE SAVE BUTTON? Best regards Jürgen Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 19, 2015 Share Posted June 19, 2015 Please try to not use uppercase writing. It's not that great to read. To answer the question: Use this to inject what ever logic you need just before a page gets saved. https://processwire-recipes.com/recipes/extending-page-save-process/ 1 Link to comment Share on other sites More sharing options...
diogo Posted June 19, 2015 Share Posted June 19, 2015 You can do anything after pressing the save button Just create a module that hooks on save and do all the magic there. I don't have time to help you with the code now, but I'm sure someone will step in. You can also have a look at the code of any module in the directory that operate on page save. Consider also playing with the visibility options on the field settings. Might make sense in your case. Link to comment Share on other sites More sharing options...
Juergen Posted June 19, 2015 Author Share Posted June 19, 2015 Thank you diogo for your answere. The visibility on field dependencies is quite a possibility but.... 1) in this case the value is still stored in the DB and will be also fetched via the search engine (I mean my site search not Google ). Thats one reason why I want to get rid of it. 2) I use Pagetable for all the prices in my pricelist - so every price item is one single page. And in the pagetable I have the column for the offer price. So it contains always the value of the offer price if it is filled out (independent if the price is standard price or not) - this could be confusing for customers. Link to comment Share on other sites More sharing options...
Juergen Posted June 19, 2015 Author Share Posted June 19, 2015 Thank you LostKobrakai - I will try this. Link to comment Share on other sites More sharing options...
Juergen Posted June 19, 2015 Author Share Posted June 19, 2015 Please try to not use uppercase writing. It's not that great to read. To answer the question: Use this to inject what ever logic you need just before a page gets saved. https://processwire-recipes.com/recipes/extending-page-save-process/ I have tried to install the module as it is (only for testing purpose) and I always get the following error messages if I want to install it: Fatal error: Class 'HookAfterPageSave' not found in /home/.sites/24/site1275/web/wire/core/Modules.php on line 392 Error: Class 'HookAfterPageSave' not found (line 392 of /home/.sites/24/site1275/web/wire/core/Modules.php) This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged. The file is placed in the site/modules/HookAfterPageSave/HookAfterPageSave.module Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 19, 2015 Share Posted June 19, 2015 HookAfterPagesSave - little things matter. 2 Link to comment Share on other sites More sharing options...
Juergen Posted June 19, 2015 Author Share Posted June 19, 2015 Wow, you have eyes like an eagle - I havent seen this small mistake - now it works! Thanks!!!!!! Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 19, 2015 Share Posted June 19, 2015 Weren't the eagle eyes. I wrote the recipe and knew there's nothing wrong with it. That fact combined with the error message did point to the issue. Link to comment Share on other sites More sharing options...
Juergen Posted June 19, 2015 Author Share Posted June 19, 2015 So, now it works as expected with this piece of code, but I cannot find a explanation how to delete the value of the specific field: if(($page->template == "pricelistitem") AND ($page->pricetype == "1")){ $this->message("Angebotspreis wurde entfernt"); CODE TO REMOVE THE VALUE OF THE FIELD "OFFERPRICE"??? } The message will be shown if the pricetype field is 1 (= standard price). How can I delete the value of the field "offerprice" so the field will be blank?? Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 19, 2015 Share Posted June 19, 2015 Overwrite it with the blank state value: $page->offerprice = ""; Link to comment Share on other sites More sharing options...
Juergen Posted June 19, 2015 Author Share Posted June 19, 2015 Thanks I have founded it out too a moment ago, but you were a little bit quicker - works fine! 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