forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: travelbuff on January 20, 2013, 05:49:39 am

Title: Required Fields Specific
Post by: travelbuff on January 20, 2013, 05:49:39 am
I'm using the required fields for registration code. previously listed in the forum that works great.  Is there anyway to make them more specific for validation?  For example a zip code field, to take only numerals?  I'm having problems with spammers registering with just jibberish in my required fields and I would like to make it just a little harder for them to spam me.  I have the captcha on also.

Any idea's?
Title: Re: Required Fields Specific
Post by: Αndré on January 21, 2013, 12:36:11 pm
Please post a link to the mod/plugin you use.
Title: Re: Required Fields Specific
Post by: travelbuff on January 21, 2013, 02:27:08 pm
Andre

I'm not using a plugin, just the coding that was supplied in the forum to make the fields mandatory.  I want to validate the fields also.  Is there a plugin for field validation, I did not see one?
Title: Re: Required Fields Specific
Post by: phill104 on January 21, 2013, 02:40:16 pm
Please post a link to where you got the code from. There are so many mods out there we just cannot know exactly which you are using.
Title: Re: Required Fields Specific
Post by: travelbuff on January 21, 2013, 02:50:51 pm
Sorry,
I'm using this bit of code; http://forum.coppermine-gallery.net/index.php/topic,33757.0.html (http://forum.coppermine-gallery.net/index.php/topic,33757.0.html). 
Title: Re: Required Fields Specific
Post by: Αndré on January 21, 2013, 03:10:27 pm
That mod was designed for cpg1.4.x. It won't work for cpg1.5.x because the superglobal $_POST doesn't exist. I assume you're still running cpg1.4.x (which is unsupported for over two years now)? However, a simple preg_match should do the trick.
Title: Re: Required Fields Specific
Post by: travelbuff on January 21, 2013, 03:18:50 pm
Andre

Yes I was a little behind.  I should state it did work.  I actually did the latest upgrade yesterday.  Could you explain the simple preg_match and how that would fit into the code?
Title: Re: Required Fields Specific
Post by: Αndré on January 21, 2013, 03:23:27 pm
Sorry, I looked at the wrong code line. Actually, the lines you have to find look different in cpg1.5.x, so the mod still works if you find the correct lines:
Code: [Select]
    $profile1 = $superCage->post->getEscaped('user_profile1');
    $profile2 = $superCage->post->getEscaped('user_profile2');
    $profile3 = $superCage->post->getEscaped('user_profile3');
    $profile4 = $superCage->post->getEscaped('user_profile4');
    $profile5 = $superCage->post->getEscaped('user_profile5');
    $profile6 = $superCage->post->getEscaped('user_profile6');


Could you explain the simple preg_match and how that would fit into the code?
That's currently not possible as I don't know which data validates each field. Additionally, please post the modified code block.
Title: Re: Required Fields Specific
Post by: travelbuff on January 21, 2013, 04:00:07 pm
Ok here is what I have now;
Code: [Select]
    $user_name = trim(get_post_var('username'));
    $password = trim(get_post_var('password'));
    $password_again = trim(get_post_var('password_verification'));
    $email = trim(get_post_var('email'));
    $profile1 = $superCage->post->getEscaped('user_profile1');
    if (!$profile1) $error .= "<li>it's mandatory to fill in your City and State";
    $profile2 = $superCage->post->getEscaped('user_profile2');
    if (!$profile2) $error .= "<li>it's mandatory to fill in your Gender";
    $profile3 = $superCage->post->getEscaped('user_profile3');
    if (!$profile3) $error .= "<li>it's mandatory answer Yes or No";
    $profile4 = $superCage->post->getEscaped('user_profile4');
    if (!$profile4) $error .= "<li>it's mandatory to enter your birth year";
    $profile5 = $superCage->post->getEscaped('user_profile5');
    if (!$profile5) $error .= "<li>it's mandatory answer Yes or No";
    $profile6 = $superCage->post->getEscaped('user_profile6');
    $agree_disclaimer = $superCage->post->getEscaped('agree');
    $captcha_confirmation = $superCage->post->getEscaped('confirmCode');
I would like to make the birth year validate 4 digits and to validate the yes or no answers to be "yes or no".
Title: Re: Required Fields Specific
Post by: travelbuff on January 21, 2013, 11:10:18 pm
Would something like this work.  I'm not much on php coding?  Any help would be greatly appreciated.  ;)

Code: [Select]
$profile2 = $superCage->post->getEscaped('user_profile2');
    if ((!$profile2)(!in_array(strtolower(trim($_POST['gender'])),array('male','female','couple')) $error .= "<li>It's mandatory to fill in your Gender";
Title: Re: Required Fields Specific
Post by: Αndré on January 22, 2013, 09:17:36 am
Gender and yes/no:
Code: [Select]
if (!in_array(strtolower(trim($profile2)), array('male','female','couple'))) $error .= "<li>It's mandatory to fill in your Gender";
Year of birth:
Code: [Select]
if (!preg_match('/[0-9]{4}/', $profile4)) $error .= "<li>it's mandatory to enter your birth year";