Jump to content
onjegolders

Password field required compatibility?

Recommended Posts

Is the password field compatible with the "required" option?

I only ask because if I make it a required option when editing a page if I haven't changed the password, it throws a required error. Obviously I'd like for the user to be able to leave it blank and leave the password how it is.

The problem is if I don't make it required then I may end up without a password at all.

Is this something I should look to triggering via a module?

Thanks.

Share this post


Link to post
Share on other sites

Hi onjegolders,

Are you working with the admin backend? I gave your case a try with the API:

$page->of(false);
$page->requiredField = "";
$page->save();
 

Nothing happened. Literally nothing: no errors, no field update.

Share this post


Link to post
Share on other sites

Thanks Valery, yes this is in the backend. On page save, the required error still gets called even if previously a password has been set. This must be because the password field is empty and it's only if a user fills it in that it gets reset.

Share this post


Link to post
Share on other sites

I took a peek at the system password field settings just out of curiosity.

It is not required.

And it's actually possible to create a user without a password. But they won't be able to log in: PW would silently redirect them back to the login page.

Share this post


Link to post
Share on other sites

Thanks Valery. 

I think I should specify, I'm adding the password field to a different page and adding the required value myself in the file settings.

Essentially it's so that my client can create a "member" while also creating a user without having to also remember to go to Access->Users and add one there.

Ideally the password field would be required initially when they add the page but perhaps thereafter not required. Either that or the value of a password field on the edit page template should not be empty.

Share this post


Link to post
Share on other sites

If all of this happens in the backend and the field is "required", the PW backend will not allow to blank it. You would have to write your own template for it to work. You won't even need the "required" option then.

Sorry if that's a poor solution. Maybe someone else can come up with a bright idea?

  • Like 1

Share this post


Link to post
Share on other sites

Thanks anyway Valery, it's useful having different thoughts on it!

I just imagined that as it's part of the core there must be some expected behaviour in this scenario.

Share this post


Link to post
Share on other sites

The only time you'd want to make the password field required is when using it for a new user form or something like that. Otherwise, I'd suggest not making it a required field unless you want people to change their password every time. I'm not positive about what your context is in this case, but because the built-in password field is designed for a very specific purpose, you might just want to use your own markup for a password field. Or, if using an InputfieldForm, you can use InputfieldText and change the type attribute to 'password':

$pass = $modules->get('InputfieldText'); 
$pass->attr('type', 'password'); 
$pass->attr('name', 'pass'); 
$pass->label = 'Your password';
$pass->required = (bool) whateverConditionYouWant(); 

Share this post


Link to post
Share on other sites

Thanks Ryan,

The context would be, like you said, a first time adding of a password for a user. Except a page (student) is being mapped to a user. So if the admin wants to update a student's password, they could also do it from the student page.

Obviously making it required will be unhelpful because it's only required once, unless the password field had some way of knowing that it hadn't been overriden this time but that it was set and not "blank".

I think failing that, the best way is for me to make it not required and the admin will have to remember if someone can't login, it's probably because they failed to assign them a password.

Share this post


Link to post
Share on other sites

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.

  • Similar Content

    • By Pip
      Hi, Everyone! 
      I'm currently working on a page reference field and set it for multiple pages (AsmSelect) for the input. Is there a way for me to add an image field (aka Avatar) and the title of page in the radio button? 
      I used the field name enclosed in the { }. Didn't work. It appeared a text instead. 
      Thanks in advance and hope to hear from you soon!
    • By EyeDentify
      Hello dear PW gurus.

      I have stumbled over a strange error that i all of sudden got when trying to upload an image to a images field on a page.
      There where images allready stored in the field that i wanted to keep, but during the upload the error apear and after that all images are gone from the field and i can´t upload any, i just get the error every time.
      I am running ProcessWire 3.0.153 dev.
      Update:
      After looking in the assets folder i find the folder for the page and the image files seems to be there including the ones i tried to upload when the error occured.
      But they don´t show up in the images field in the page editor.
       
      The error reported:
       
      SQLSTATE[01000]: Warning: 1265 Data truncated for column 'ratio' at row 1 And here is a screenshot of the event:

      The TracyDebugger Error reporting:

      I hope you fine folks could point me in a direction.
      But it seems our old pal set_time_limit() is back.

      Regards, EyeDentify
    • By DV-JF
      Hey all, hope you're feeling well these days!
      Short question: Under "Setup > Templates" it's possible to sort the templates by last modified. Is this possible for fields view to?
      Long explanation:
      Currently I am in the process of programming a reusable template and often have to copy several fields & templates from different PW installations into my "master version".
      Therefore it would be good to see already in the field list when the last modification has taken place.
      Stay healthy & don't forget to wash you hands - many greets!
    • By Robin S
      This module is inspired by and similar to the Template Stubs module. The author of that module has not been active in the PW community for several years now and parts of the code for that module didn't make sense to me, so I decided to create my own module. Auto Template Stubs has only been tested with PhpStorm because that is the IDE that I use.
      Auto Template Stubs
      Automatically creates stub files for templates when fields or fieldgroups are saved.
      Stub files are useful if you are using an IDE (e.g. PhpStorm) that provides code assistance - the stub files let the IDE know what fields exist in each template and what data type each field returns. Depending on your IDE's features you get benefits such as code completion for field names as you type, type inference, inspection, documentation, etc.
      Installation
      Install the Auto Template Stubs module.
      Configuration
      You can change the class name prefix setting in the module config if you like. It's good to use a class name prefix because it reduces the chance that the class name will clash with an existing class name.
      The directory path used to store the stub files is configurable.
      There is a checkbox to manually trigger the regeneration of all stub files if needed.
      Usage
      Add a line near the top of each of your template files to tell your IDE what stub class name to associate with the $page variable within the template file. For example, with the default class name prefix you would add the following line at the top of the home.php template file:
      /** @var tpl_home $page */ Now enjoy code completion, etc, in your IDE.

      Adding data types for non-core Fieldtype modules
      The module includes the data types returned by all the core Fieldtype modules. If you want to add data types returned by one or more non-core Fieldtype modules then you can hook the AutoTemplateStubs::getReturnTypes() method. For example, in /site/ready.php:
      // Add data types for some non-core Fieldtype modules $wire->addHookAfter('AutoTemplateStubs::getReturnTypes', function(HookEvent $event) { $extra_types = [ 'FieldtypeDecimal' => 'string', 'FieldtypeLeafletMapMarker' => 'LeafletMapMarker', 'FieldtypeRepeaterMatrix' => 'RepeaterMatrixPageArray', 'FieldtypeTable' => 'TableRows', ]; $event->return = $event->return + $extra_types; }); Credits
      Inspired by and much credit to the Template Stubs module by mindplay.dk.
       
      https://github.com/Toutouwai/AutoTemplateStubs
      https://modules.processwire.com/modules/auto-template-stubs/
    • By DV-JF
      Hi, 
      I'm using this kind of setup (https://processwire.com/blog/posts/language-access-control-and-more-special-permissions/#language-page-edit-permissions) in order to control the page edit permissions. Now I'm wondering if it's possible to hide the "none-ediable" language-tabs instead of striking them through.

      Many greets...
       
×
×
  • Create New...