Required Fields Specific Required Fields Specific
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Required Fields Specific

Started by travelbuff, January 20, 2013, 05:49:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

travelbuff

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?

Αndré

Please post a link to the mod/plugin you use.

travelbuff

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?

phill104

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.
It is a mistake to think you can solve any major problems just with potatoes.


Αndré

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.

travelbuff

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?

Αndré

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:
    $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');



Quote from: travelbuff on January 21, 2013, 03:18:50 PM
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.

travelbuff

Ok here is what I have now;
    $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".

travelbuff

Would something like this work.  I'm not much on php coding?  Any help would be greatly appreciated.  ;)

$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";

Αndré

Gender and yes/no:
if (!in_array(strtolower(trim($profile2)), array('male','female','couple'))) $error .= "<li>It's mandatory to fill in your Gender";

Year of birth:
if (!preg_match('/[0-9]{4}/', $profile4)) $error .= "<li>it's mandatory to enter your birth year";