perl - Checking for alphanumeric characters and getting input from HTML form -


i'm new programming in perl , have couple of compilation issues can't seem resolve. program gets input html form.

question: should form use post or method?

<form action="./cgi-bin/perl.pl" method="get">      <br>      full name: <br><input type="text" name="full_name" maxlength="20"><br>      username: <br><input type="text" name="user_name" maxlength="8"><br>      password: <br><input type="password" name="password" maxlength="15"><br>      confirm password: <br><input type="password" name="new_password" maxlength="15"><br> 

i open csv file, write value of user_name array , number of checks on user's input.

problem #1: need check full_name, user_name, password, , new_password alphanumeric or space keep getting multiple errors like:

use of uninitialized value $full_name in string eq @ perl.pl line 33 

i don't think i've used cgi correctly these values form. believe i'm not correctly checking alphanumeric characters. how can resolve this?

problem #2: need redirect user specific webpage if passwords don't match , if username taken. used meta redirect it's not doing successfully. how can display proper error page?

this code:

#!/usr/bin/perl  use cgi qw(:standard); use strict; use warnings;  print "content-type: text/html\n\n";  #opening members.csv reading $file = '/home/2014/amosqu/public_html/cgi-bin/members.csv'; open(my $csv, '<', $file)  || die "could not open file";  #getting these html form $full_name = param('full_name'); $user_name= param('user_name'); $password = param('password'); $new_password = param('new_password');  @users = ();  #splitting each line of csv file foreach (<$csv>) {      chomp;      @fields = split (/\,/);      push @users, $fields[1]; #put usernames inside of array }  close $csv;  #opening members.csv appending open(my $fh, '>>', $file) || die "could not open file";  #source of problem 1 #checking values alphanumeric if(($full_name && $user_name && $password && $new_password) eq /\a[[:alnum:]]+\z/) {       #if passwords don't match, redirect error page       if($password ne $new_password){          print qq(<html>\n);          print qq(<head>\n);          print qq(<title> passwords don't match. </title> \n);          print qq{<meta http-equiv="refresh"content="5;url="http://www.cs.mcgill.ca/~amosqu/registration.html">\n};          print qq(</head>\n);          print qq(<body>\n);          print qq(<b><center> passwords don't match </b></center>\n\n);          print qq(</body>\n);          print qq(</html>\n);      }       #if match, check user name isn't in members.csv       else {            if(grep (/$user_name/, @users)) {              print qq(<html>\n);              print qq(<head>\n);              print qq(<title> sorry username taken. </title>\n);              print qq{<meta http-equiv="refresh"content="5;url="http://www.cs.mcgill.ca/~amosqu/registration.html">\n};              print qq(</head>\n);              print qq(<body>\n);              print qq(<b><center> username taken. </b></center>\n\n);              print qq(</body>\n);              print qq(</html>\n);         }         #if isn't in members.csv append values file         else {               print $fh "$full_name, $user_name, $password \n";        }     } }  close $fh; 

this should going. there number of issues code don't stop working, current wisdom not use cgi @ roll you.

  • use get unless have reason use post

  • the problem here

    if(($full_name && $user_name && $password && $new_password) eq /\a[[:alnum:]]+\z/) { 

    you using boolean && operation combines truth of 3 variables, , checking whether that, string, equal result of matching contents of $_ against regular expression.

    you must check each of variables individually, , use binding operator =~ test them against regex. bad form use posix character classes. suggest use grep, this

    my $mismatch = grep /[^a-z0-9]/i, $full_name, $user_name, $password, $new_password; 

    now, $mismatch true if of variables contain non-alphanumeric character. (strictly, set number of variables have a non-alphanumeric character, 0 (false) if none of them do.)

    then can say

    if (not $mismatch) { ... } 
  • it looks need else builds separate page.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -