Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

How do I make a form field required for a Perl Chat Script?

by SolitudeDude (Initiate)
on Feb 22, 2008 at 17:25 UTC ( #669611=perlquestion: print w/replies, xml ) Need Help??

SolitudeDude has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, New member here & also very new to Perl. I am running a CGI/Perl chat script on my website and have a problem. One of my rules is that all members register a valid email address during the registration process, however some users are able to get around this because there is nothing there to make the field "mandatory", they can simply leave it blank and still get into the chat. This chat comes with it's own registration & login forms that send the data to the CGI part of the chat and I would really like to know how to make at least the email field "required" with an error message if they leave it blank....any ideas? If needed, feel free to examine the chat yourself at www.decenttalk.org, or the script's homepage which is www.ralfchat.com It may take a little time to understand this program as it took me a while....it's a very sophisticated script but has excellent features. Thanks in advance for your time! Allen
  • Comment on How do I make a form field required for a Perl Chat Script?

Replies are listed 'Best First'.
Re: How do I make a form field required for a Perl Chat Script?
by olus (Curate) on Feb 22, 2008 at 17:33 UTC

    Your registration form has an 'action' attribute that sends the information filled in the form fields to your script, which then parses them.

    In that script of yours you can do all sorts of validations, namelly to check if any value is present and if it is a valid email. If it isn't, you can send an error message back to the user and display the form again.

    Look at the CGI module, if you haven't already, to see how you can capture the information being passed.

Re: How do I make a form field required for a Perl Chat Script?
by Popcorn Dave (Abbot) on Feb 22, 2008 at 17:50 UTC
    The generic answer is that there are at least two ways to do what you're attempting. One is to use JavaScript to check that all fields that you require are filled in and not let the page proceed until that requirement is met.

    The purely Perl option is to use self referencing CGI, similar to what olus said to do your parsing and not let the script move on until your conditions are met.

    $|++; use strict; use CGI; my $query = CGI->new(); print $query->header; if ( !$query->param() ) { # no parameters so display your login page my_login_form(); } else { #since you've got parameters, make sure all that you require are fil +led in and process accordingly.

    If your not getting all the fields filled in you want, you just redisplay the login form. If you do get all your fields filled in and verified, then you can proceed.

    HTH!


    Revolution. Today, 3 O'Clock. Meet behind the monkey bars.

    I would love to change the world, but they won't give me the source code

      The generic answer is that there are at least two ways to do what you're attempting. One is to use JavaScript to check that all fields that you require are filled in and not let the page proceed until that requirement is met.

      I think there are two ways you are required to do it in that case. Client-side stuff is great for user experience and helping to keep load off the server but it's completely useless for validating things in the end because they can be sent by a hacker or "broken" browser anyway. Verify and block bad submissions in the client if you can but remember you should do the same thing on the server side either way.

        You're right, but I thought the OP was asking how to make sure that a field was filled in before progressing. I may have misread the OP's intent.


        Revolution. Today, 3 O'Clock. Meet behind the monkey bars.

        I would love to change the world, but they won't give me the source code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://669611]
Approved by olus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2019-05-23 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (147 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!