Home › Forums › Quform WordPress › required fields
- This topic has 7 replies, 2 voices, and was last updated 8 years, 3 months ago by Ally.
- AuthorPosts
- January 7, 2016 at 5:01 pm #17852patdundeeParticipant
Hi Guys
I have another strange one for you 🙂
Two fields
Field 1 Drop Down
Field 2 Text BoxIf drop down is not selected but there is an entry in the text box, this would be accepted and vica versa.
However I only need the (Required) to appear if the user does not either choose from the select or enter into the text box. So long as they have done one or the other the form can submit. If they fail to do either an alert must come up saying one or the other field is required.
Is this achievable?
Many thanks
Patrick- This topic was modified 8 years, 4 months ago by patdundee.
January 13, 2016 at 10:55 am #17906AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
January 13, 2016 at 1:24 pm #17929patdundeeParticipantHi Ally
That’s great (As always). Is there a way we can add to the to make them choose one or the other and not both?
Kind regards
PatrickJanuary 13, 2016 at 1:50 pm #17933AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
January 13, 2016 at 2:05 pm #17936patdundeeParticipantPerfect 🙂
It is amazing how you can cutomise this form. I have got quite a bit of customisation in place for them. Have to always make sure I have a back up of everything before i do form updates. (Just in case lol).
Many thanks
PatrickJanuary 13, 2016 at 2:14 pm #17937patdundeeParticipantOops, spoke to soon
This is the test site and url. There is a small issue that the required notice does not disappear and it retains the selected values in all fieldstest.trustedweddingsuppliers.co.uk/wedding-suppliers-services
The custom validators and custom required field are in place for Service and Keyword (13_4) and (13_6) respective
Here are the codes put n place
On functions.php
//Key Word Search function my_custom_required1($form) { $dropdown = $form->getElement('iphorm_13_4'); $text = $form->getElement('iphorm_13_6'); if (!$dropdown->isEmpty()) { $text->setRequired(false); } if (!$text->isEmpty()) { $dropdown->setRequired(false); } } add_action('iphorm_pre_validate_13', 'my_custom_required1'); //Validator for both fields above function my_custom_dropdown_validator1($valid, $value, $element) { if (!$element->getForm()->getElement('iphorm_13_4')->isEmpty()) { $element->addError('Please choose from this menu or search by keword only below. You cannot use both.'); $valid = false; } return $valid; } add_filter('iphorm_element_valid_iphorm_13_4', 'my_custom_dropdown_validator1', 10, 3); function my_custom_text_validator2($valid, $value, $element) { if (!$element->getForm()->getElement('iphorm_13_6')->isEmpty()) { $element->addError('Please either enter a keyword or use the drop down menu above only. You cannot use both.'); $valid = false; } return $valid; } add_filter('iphorm_element_valid_iphorm_13_6', 'my_custom_text_validator2', 10, 3); //End Validator //End Keyword Search
and the java as given above is on the form in a html field
Kind regards
PatrickJanuary 13, 2016 at 2:56 pm #17940patdundeeParticipantHi Ally
I have solved the issue 🙂
Changed the code in each section from this
if (!$element->getForm()->getElement('iphorm_13_4')->isEmpty()) {
To this for 13_4
if (!$element->getForm()->getElement('iphorm_13_4')->isEmpty() && !$element->getForm()->getElement('iphorm_13_6')->isEmpty()) {
And from this for 13_6
if (!$element->getForm()->getElement('iphorm_13_6')->isEmpty()
To this
if (!$element->getForm()->getElement('iphorm_13_6')->isEmpty() && !$element->getForm()->getElement('iphorm_13_4')->isEmpty()
All working now 🙂
Kind regards
PatrickJanuary 13, 2016 at 3:02 pm #17941AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.