LostKobrakai Posted August 9, 2015 Share Posted August 9, 2015 I'm just experimenting with an unique email per user system. Now I wondering if there is a way to have a required field like the name field? Required in that the page cannot and will not be saved without the email field being uniquely populated. To ensure uniqueness I'm currently using a fork of FieldtypeTextUnique. Link to comment Share on other sites More sharing options...
horst Posted August 9, 2015 Share Posted August 9, 2015 when under fields: edit field -> tab input -> required [x] you can tip the checkbox, (like with the title field). Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 9, 2015 Author Share Posted August 9, 2015 That's why I specifically added the "like the name field" part. Having a field required by this checkbox does not prevent a page/user from being created/saved, which is what I want to happen. 1 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted August 9, 2015 Share Posted August 9, 2015 (edited) I do not think the default required checkbox is sufficient for that, since even tho the field becomes a required value, the page will just save. It can be achieved with a simple process autoload module that hooks in to Pages save() method as a before hook. $this->pages->addHookBefore('save', $this, 'yourMethodToCheckTheValue'); Create a method that checks the validity of the value. When the value is invalid you can replace the method you are hooking so that it will not continue and save the page, perhaps throw in a nice error rmessage for the admin to read. Edited August 10, 2015 by Raymond Geerts 1 Link to comment Share on other sites More sharing options...
teppo Posted August 10, 2015 Share Posted August 10, 2015 (edited) At the moment Raymond's answer seems to be the only working solution. This is essentially the same thing that @thetuningspoon posted in this issue: https://github.com/ryancramerdesign/ProcessWire/issues/1121, and it's been one of the very few major headaches for me since the beginning. In my opinion when something is set as "required", it should mean "required", not "recommended". The page should not be saved under any circumstances unless all required fields are filled in. From what I can remember, this has been discussed before, and the general idea was something along the lines of "a page with a lot of fields and couple of them required could result in a lot of lost data if it wasn't saved when one of the required fields was left empty". Essentially the page can be saved, but left unpublished, and thus considered as "temporary storage". This, again in my opinion, would be better solved by storing those values not within actual pages, but a) some temporary alternative, b) within browser memory, or c) within session variables. Of course that would be a new concept for ProcessWire, and Ryan might also have other reasons to stick with the current behaviour Just my (relatively unhelpful) two cents. Edit: Just wanted to add that one specific issue with the current system is that once I fill in all fields I can publish the page, but after that I can clear required fields, save the page, and it remains published. This, at the very least, is not what I'd expect. Edited August 10, 2015 by teppo 2 Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 10, 2015 Author Share Posted August 10, 2015 @teppo There are surely issues with this type of system, but actually I was thinking about something even more rigid. I thought of having an additional field like name, that is required to be set before creating a page, that's added to the PageAdd form, is unique and does prevent saving when invalid / empty. But I think this would only be useful for a unique username and unique email situation for users. I cannot think of other cases, where such a system would be beneficial as well. Maybe I'll just stick to the email-as-name tactic as I've currently no real need for usernames. 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