/    Sign up×
Community /Pin to ProfileBookmark

Form field validation

Hi Everyone,
I have a php validation for my form, but i am looking for a way to add a few lines to it in order to achieve the following two objectives:

  • 1.

    To validate password field to require at least 8 characters long

  • 2.

    There are two radio buttons A and B, and a form field B1; if radio A is checked, form field B1 is not required, but if radio B is checked then form field B1 is required.

  • Any help on this please. Thanks.

    to post a comment
    PHP

    7 Comments(s)

    Copy linkTweet thisAlerts:
    @kurbyJun 21.2010 — 1) [code=php]if(strlen($_POST['password']) < 8))
    $error = 'Password needs to be 8 chars.';[/code]



    2) [code=php]if($_POST['radio'] == 'B')
    {
    if(empty($_POST['B1']))
    {
    $error = 'B1 is empty, fill it out dummy.';
    }
    }[/code]
    Copy linkTweet thisAlerts:
    @akluch2authorJun 22.2010 — Thanks so much Kurby.

    The first script validate the password field perfect, but the second (conditional if) is giving me some error warning and page won't load. I am not sure if its caused by my combination of other scripts. In between my other script i have this: [CODE]}elseif($data['UseExtRegForm']&&!($_POST['radio']=='B'))
    {
    if(empty($_POST['B1'])
    {
    $error = 'B1 is empty, fill it.';
    }[/CODE]

    Now if i remove this line: if(empty($_POST['B1']), page will load without the error warning but the validation won't go through. Any idea what i should do? Thanks.
    Copy linkTweet thisAlerts:
    @criterion9Jun 22.2010 — You are missing a closing brace:

    if(empty($_POST['B1'])

    {

    $error = 'B1 is empty, fill it.';

    [B][COLOR="Red"]}[/COLOR][/B]
    [/quote]
    Copy linkTweet thisAlerts:
    @akluch2authorJun 22.2010 — Thanks for your reply criterion9. I have check my script there is no missing closing brace. Here is an extract from my script, blue purtion is the one in question: }elseif($data['UseExtRegForm']&&!$post['name']){

    $data['Error']='Please enter your last name.';

    [COLOR="Blue"]}elseif($data['UseExtRegForm']&&!($_POST['radio'] == 'B')){

    if(empty($_
    POST['B1'])){

    $data['Error']=''B1 is empty, fill it .';[/COLOR]


    }elseif($data['UseExtRegForm']&&!$post['address']){

    $data['Error']='Please enter your valid address.';[/QUOTE]
    I get a Parse error. I tried this changes in red, i still get error:
    [COLOR="blue"] }elseif($data['UseExtRegForm']&&![COLOR="Red"]$post[/COLOR]['radio'] == 'B'){

    if[COLOR="red"](!$post[/COLOR]['B1']){

    $data['Error']=''B1 is empty, fill it .';

    }[/COLOR]
    [/QUOTE]
    I think the problem is in the line but i can't solve it if(empty($_POST['B1'])){[/QUOTE]if(!$post['B1']){[/QUOTE]
    Copy linkTweet thisAlerts:
    @NogDogJun 22.2010 — This line has two single quotes at the start of the error message (easier to see if you use this forum's [noparse][code=php]...[/code][/noparse] tags):
    [code=php]
    $data['Error']=''B1 is empty, fill it .';
    [/code]

    Should be:
    [code=php]
    $data['Error']='B1 is empty, fill it .';
    [/code]

    Also, note that [b]$post['B1'][/b] is not the same as [b]$_POST['B1'][/b].
    Copy linkTweet thisAlerts:
    @criterion9Jun 23.2010 — You are still missing a closing brace....let me show with indention:
    [code=php]
    }elseif($data['UseExtRegForm']&&!$_POST['name']){
    $data['Error']='Please enter your last name.';
    }elseif($data['UseExtRegForm']&&!($_POST['radio'] == 'B')){
    if(empty($_POST['B1'])){
    $data['Error']='B1 is empty, fill it .';
    }
    }elseif($data['UseExtRegForm']&&!$_POST['address']){
    $data['Error']='Please enter your valid address.';
    [/code]

    I added the "}" after "$data['Error']='B1 is empty, fill it .';" along with the fix for the error NogDog pointed out. (Plus the $post['address'] instead of $_POST['address'], etc).
    Copy linkTweet thisAlerts:
    @akluch2authorJun 23.2010 — Thanks a lot guys. My script is working now. NogDog and criterion9, thanks for your close observation. kurby, thanks a lot for you help.
    ×

    Success!

    Help @akluch2 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...