Ask the community

This is a community support forum where you can ask
questions and interact with other PremiumPress Customers.

Make country field mandatory


  • Carlos
    Newbie 12 points
    July 18, 2013 at 2:25 am

    Hi guys

    I really really need to make the country field on submit page mandatory, but have no idea how… Can someone help please?

    Cheers

  • Mark Fail
    Mark Fail
    Super Guru 12,819 points
    July 18, 2013 at 2:41 am

    You would need to add code to do this, its not possible without customization work.


  • Carlos
    Newbie 12 points
    July 24, 2013 at 1:09 am

    Yes Mark I understand I need to add that validation to

    function CheckFormData()

    I can see that there’s an array

    $dfs = get_option('default_form_fields');

    which contains the default form fields for validation

    My question is, is country field on that array so I can validate its value? If it’s not how can I put it there? If it’s there, how can I validate its value?

    I tried to add to CheckFormData function:

    var country = document.getElementById("countrybox");
    if(country.value) == ''){
    	alert('You must select your country');
    	title.style.border = 'thin solid red';
    					title.focus();
    					return false;
    	}

    But it didn’t work…. And even breaks all the other validations for the other field….

    Any idea why?

    Cheers


  • Carlos
    Newbie 12 points
    July 24, 2013 at 1:47 am

    OK I had an error

    if(country.value) == ''){

    had an extra )

    fixed it

    It now returns the validation error if no country is select, but goes forward to the next page anyway… 😥

    any idea why?

    cheers


  • Carlos
    Newbie 12 points
    July 24, 2013 at 2:00 am

    OK i managed to get it to validate the country, final code for CheckFormData function is above.

    function CheckFormData(){
    
    //var descrip = document.getElementById("form_description");
    //var website = document.getElementById("form_url");
    
    	
    
      <?php if($dfs['title'] != "1"){ ?>
      var title 	= document.getElementById("form_title"); 
    	if(title.value == ''){
    					alert('<?php echo $PPT->_e(array('validate','7')); ?>');
    					title.style.border = 'thin solid red';
    					title.focus();
    					return false;
    	}
    	<?php } ?>
    	<?php if($dfs['excerpt'] != "1"){ ?>
    	var short 	= document.getElementById("form_short");
    	if(short.value == ''){
    					alert('<?php echo $PPT->_e(array('validate','8')); ?>');
    					short.style.border = 'thin solid red';
    					short.focus();
    					return false;
    	}
    	<?php } ?>
    	<?php  if($dfs['tags'] != "1"){ ?>
    	var tag 	= document.getElementById("form_tags");
    	if(tag.value == ''){
    					alert('<?php echo $PPT->_e(array('validate','9')); ?>');
    					tag.style.border = 'thin solid red';
    					tag.focus();
    					return false;
    	} 
    	<?php }  ?>
    	<?php if($dfs['email'] != "1"){ ?>
    	var email1 	= document.getElementById("form_email");
    	if(email1.value == ''){
    					alert('<?php echo $PPT->_e(array('validate','3')); ?>');
    					email1.style.border = 'thin solid red';
    					email1.focus();
    					return false;
    	} else {
    	
    		if( !isValidEmailAddress( email1.value ) ) {
    	
    			alert('<?php echo $PPT->_e(array('validate','3')); ?>');
    			email1.style.border = 'thin solid red';
    			email1.focus();
    			return false;
    		}
    	}
    	<?php  } ?>
    	
    	var country = document.getElementById("countrybox");
    	if(country.value == ''){
    	alert('You must select your country');
    	title.style.border = 'thin solid red';
    					title.focus();
    					return false;
    	}
    	
    	<?php echo $PPTDesign->CustomRequiredFields(); ?>	
    	
    	
    			
    return true;
    }
  • Mark Fail
    Mark Fail
    Super Guru 12,819 points
    July 24, 2013 at 3:47 am

    thanks for sharing

Viewing 6 posts - 1 through 6 (of 6 total)