- Posts: 28
COMMUNITY FORUM
Problems with field validation
- Alan Campbell
-
Topic Author
- Offline
- Junior Member
I'm having some trouble with K2 Extra Fields.
I have a front end editing form that I want all fields to be required and need to validate the data entered. Unfortunately, validation isn't working.
I have had this problem since I had vanilla K2 plus vanilla Joomla. I tried lots of different was to get around it to no avail.
- Using different templates
- Disabling templates on the user form
- Using the Joomla validation (which is turned on in the example below but has no effect)
- JQuery no-conflict mode
To see the issue:
Go to chl.soc.srcf.net/quid/
Click on the three little bars at top-left to open the login panel.
Log in with the test credentials:
User = testymctest
Pass = test
Then go to chl.soc.srcf.net/quid/submit-a-project
The form only seems to require title and dates, despite me setting all to required in the backend.
Dates aren't validated at all and you can enter anything without validation---this causes the site to freak out whenever this item is shown with a DateTime parse error. So there's no validation on front or backend.
Can anyone help me?
Alan
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Browsing your form I can see that the textarea's are not required while, the radio buttons are.
Can you send a printscreen of the settings of a textarea field?
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Alan Campbell
-
Topic Author
- Offline
- Junior Member
- Posts: 28
Many thanks for your prompt reply.
I have uploaded a screen shot here:http://imgur.com/D2vTovT
The issue seems to be three fold:
- client side validation by JavaScript is not working, so invalid dates etc are allowed; It only prevents submission with no title
- server side validation only works for checking required dates
- the server side only adds K2Required class to some fields.
I mentioned the hacks I've tried but none were successful.
I'm not sure what I've done wrong!
Thanks for your help!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Are you using any 3rd party K2 extensions?
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Alan Campbell
-
Topic Author
- Offline
- Junior Member
- Posts: 28
This is a class I made. I'm making sub labels for the fields by parsing the label name.
This change was made after the problem with the validation was found. I also tested without it and there was no difference.
Thanks again,
Alan
Please Log in or Create an account to join the conversation.
- Alan Campbell
-
Topic Author
- Offline
- Junior Member
- Posts: 28
I've made a form with only the default template code here:
chl.soc.srcf.net/quid/ongoing-projects
Again, cient side and server side checks aren't performed.
This allows required fields (as set in the backend) to be skipped and data not validated.
As invalid dates can be entered, the site fails with a fatal error about parsing the DateTime when you view the item/category.
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
- Posts: 8743
Can you try this fix and let me know if it solves your issue ? github.com/joomlaworks/k2/commit/63b2c9a35e4cf69c2f3b78e3dde036f6ea604ddd
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Alan Campbell
-
Topic Author
- Offline
- Junior Member
- Posts: 28
Many thanks for both your help and fix. I'm not great at navigating Github so hadn't found this.
Your fix seems to have corrected the missing required fields check/css class! Thank you very much for your help on this.
Unfortunately, data is still not validated for correct data format. I tried putting in random data, including letters instead of dates,and the input is accepted which then causes the site to crash. Here is an example error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND trash = 0' at line 1 SQL=SELECT MAX(ordering) FROM o4h6s_k2_items WHERE catid = AND trash = 0
Again, the testing page is at: chl.soc.srcf.net/quid/ongoing-projects
Login testymctest
password test
Separate to this, I've also noticed that changing the category isn't the drop down menu loses all my custom template changes (I guess because the fields are reloaded via. Ajax ? ). Is this a known error?Should I start a new forum topic for it?
Pleaser can you advise of any ideas on how to fix these
Alan
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
- Posts: 8743
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Alan Campbell
-
Topic Author
- Offline
- Junior Member
- Posts: 28
Many thanks for your reply.
So, data fields aren't type-validated? As invalid data throws a fatal error, I've gotten around this by making the fields read only, relying on the calendar javascript. Just in case anyone else is looking for a semi-solution!
I have changed formats and modify presentation of (for example) the field labels. I achieved this by making a custom template for K2 and selecting it as the layout for the category.
For example, if you go to:
chl.soc.srcf.net/quid/completed-projects/item/edit/15?tmpl=component
having logged in as testymctest, pass = test, and change between Ongoing and Completed categories (NB I've renamed the category field as Project Status, it's under the Title field) - you will see that I lose my label formatting.
Thanks again for your help - I really do appreciate this!
Alan
Please Log in or Create an account to join the conversation.
- Alan Campbell
-
Topic Author
- Offline
- Junior Member
- Posts: 28
Leaving aside the type validation issue for a moment:
What template are the Ajax loaded fields generated by? If I can make the same changes to these then, hopefully, I could fix this.
Also, can I use the Ajax call to change something else o the page? For example, document.write a new form title based on the newly selected category?
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
- Posts: 8743
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Alan Campbell
-
Topic Author
- Offline
- Junior Member
- Posts: 28
Many thanks for your reply.
That's exactly what I was trying to find, thank you!
I don't quite understand the plugin system, so I think I may have to edit this file directly. I realise that this isn't ideal but will help as a temporising measure, at least.
If I do ever work it out, I'll maybe share it in case others find it useful. Although, I am very much an amateur!
Thanks so much for your support.
Alan
Please Log in or Create an account to join the conversation.