Skip to Content Skip to Menu

[SOLVED] Validate multiple fields during registration

  • fkrauth
  • fkrauth
  • OFFLINE
  • Posts: 45
  • Thanks: 7
  • Karma: 2
3 years 8 months ago - 3 years 8 months ago #323780 by fkrauth
Hi!
I have created a table in the database with fields 'memberid' 'firstname' 'lastname'.
I created an additional field for the memberid and use it in the registration form. To successfully register, memberid needs to be in the list of member ids and must match to the corresponding firstname and lastname.
User enters firstname lastname and memberid during registration. I can successfully validate (ajax) the memberid field with a DB query

SELECT * FROM `table` WHERE `memberid`='[value]' AND NOT EXISTS(SELECT * FROM `#__users` WHERE `username`='[value]') AND `firstname`='[firstname]' AND `lastname`='[lastname]'

However, when the registration form is submitted, I get an error.

What am I doing wrong?

Thanks!
Frank
Last edit: 3 years 8 months ago by krileon. Reason: Added [SOLVED] tag to subject

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
3 years 8 months ago #323792 by krileon
Replied by krileon on topic Validate multiple fields during registration
What's the error you're getting? Is memberid supposed to be username as you're currently checking [value] against memberid and username in that query.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • fkrauth
  • fkrauth
  • OFFLINE
  • Posts: 45
  • Thanks: 7
  • Karma: 2
3 years 8 months ago - 3 years 8 months ago #323800 by fkrauth
Replied by fkrauth on topic Validate multiple fields during registration
Hi Kyle,
Thanks for picking this up. And sorry for not being so precise.

- a valid username is an 'untaken' memberid (from the DB table) that matches to firstname and lastname
- I am using the memberid as fallback for the username
- during signup I ask (among other things) for firstname, lastname and memberid. I have a validation (DB Query) on the memberid field to check that the username (which will be the memberid because of fallback) is untaken and that firstname and lastname entered corresponds to the memberid in the table
- ajax validation works
- on submit of the form I get the errormessage that I also chose as ajax-error (my customized text).
- firstname and lastname are marked as "additional fields"

Can I actually use these additional fields (firstname, lastname) in the DB query for field memberid? I know, I can use [value]. But can I also use [firstname] and [lastname] here? It would be helpful for me to undstand if it 'should' work? Then I could further investigate. But maybe I am totally off-track here?

Thanks.

Frank
Last edit: 3 years 8 months ago by fkrauth.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
3 years 8 months ago #323802 by krileon
Replied by krileon on topic Validate multiple fields during registration
Yes, you can use firstname and lastname there. My guess is there's potentially a problem with the reliability of the query. Try something like the below.

Query:
Code:
SELECT COUNT(*) FROM `table` as m LEFT JOIN `#__users` as u ON u.`username` = m.`memberid` WHERE m.`memberid` = '[value]' AND m.`firstname` = '[firstname]' AND m.`lastname` = '[lastname]' AND u.`id` IS NULL
Validate On: Successful Results
Additional Fields: firstname, lastname

Note since you depend on firstname and lastname as well those absolutely need to be present during registration. If you're using single name input instead of the split firstname and lastname usages then your database table should be adjusted for that so you're only checking single input against single input.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • fkrauth
  • fkrauth
  • OFFLINE
  • Posts: 45
  • Thanks: 7
  • Karma: 2
3 years 8 months ago - 3 years 8 months ago #323806 by fkrauth
Replied by fkrauth on topic Validate multiple fields during registration
Thank you!
I changed the query and tested it with fixed values before directly against the database. It works as expected.

However, I still get the same error during ajax validation but as before on submit of the registration form.

It works fine even on submit of the form without
Code:
AND m.`firstname` = '[firstname]' AND m.`lastname` = '[lastname]'

Do you have any further idea? Firstname and lastname are both mandatory and both in sep. fields in the database.
Do you know if the validation and its result is logged somewhere?

Thanks.
Frank

EDIT: In debug mode in Joomla I could actually see the executed. sql statement.
It looks like
Code:
AND m.`firstname` = '' AND m.`lastname` = ''

So it seems as the substitutions do not work on submit of the form.
Last edit: 3 years 8 months ago by fkrauth. Reason: Entered debug information

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
3 years 8 months ago #323810 by krileon
Replied by krileon on topic Validate multiple fields during registration
Is the memberid field ordered before the firstname and lastname fields? Fields are processed in the same order as seen in the form. It's probably just an order issue. Basically you're trying to have a field access data before it has been processed and actually exists. Move the memberid field to be after firstname and lastname and it'll probably work fine.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum