required fields

Home Forums Quform WordPress required fields

This topic is: resolved
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #17852
    patdundee
    Participant

    Hi Guys

    I have another strange one for you 🙂

    Two fields
    Field 1 Drop Down
    Field 2 Text Box

    If 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.
    #17906
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #17929
    patdundee
    Participant

    Hi 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
    Patrick

    #17933
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #17936
    patdundee
    Participant

    Perfect 🙂

    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
    Patrick

    #17937
    patdundee
    Participant

    Oops, 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 fields

    test.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
    Patrick

    • This reply was modified 8 years, 3 months ago by patdundee.
    • This reply was modified 8 years, 3 months ago by patdundee.
    #17940
    patdundee
    Participant

    Hi 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
    Patrick

    #17941
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy