Xforms password confirmation password

I have a typical password, confirm the password layout with xforms: My instance is as follows:

<data> <password/> <newPassword/> <confirmPassword/> </data> 

and the inputs are as follows:

  <xf:secret ref="password"> <xf:label>Old PAssword</xf:label> </xf:secret> <xf:secret ref="newPassword"> <xf:label>New Password</xf:label> </xf:secret> <xf:secret ref="confirmPassword"> <xf:label>Confirm Password</xf:label> </xf:secret> <div> <xf:submit submission="test"> <xf:label>Change Password</xf:label> </xf:submit> </div> 

I don’t know how to verify and match newPassword with confirmPassword exactly, I know something with the <xf:bind tag, but I haven’t found how to check for equality between nodes. Please, help!

+4
source share
1 answer

You really can use xf: bind to apply restrictions. Just add the following lines to xf: model:

 <xf:bind nodeset="password" required="true()" constraint=". != ''"/> <xf:bind nodeset="newPassword" required="true()" constraint=". != ''"/> <xf:bind nodeset="confirmPassword" required="true()" constraint=". = ../newPassword"/> 

This will add the necessary markers for all three input fields, make sure that all three fields are filled, and the last two should be the same. You can add a restriction that the password and newPassword cannot be the same by adding it with 'and' to the newPassword restriction.

Personally, I like getting a little more feedback. These restrictions simply make indicators appear behind each field, without additional information. It would be better if you could display a message at the moment when you are trying to send information. But this has to do with xforms event handling, and I'm not experienced enough to tell you how to do this. There is an xforms-submit event that you can somehow catch and act on. But the most common problem is that after the feed has been deleted, you do not have or only very little opportunity to show feedback to the user before something is sent to the server.

Another option is to show conditional messages using xf: output. If you add incremental = "true" attributes to your xf: secret inputs, they will be updated every time you press a key. Just use the value attribute with a select expression in the xf: output element. Something like that:

 <xf:output value="choose(password = '' or newPassword = '' or confirmPassword = '', 'Please enter current password, new password, and confirmation of new password', '')"/> <xf:output value="choose(newPassword = '' or newPassword = confirmPassword, '', 'new password, and confirmation do not match!')"/> 

You can also add some pretty nice prints around them if you want. Other dynamic style methods are to use xf: group, but I will leave this as an exercise for you.

Finally, be sure to check all the values ​​on the server side, just make sure that no one is cheating.

NTN!

+4
source

Source: https://habr.com/ru/post/1384626/


All Articles