Click to See Complete Forum and Search --> : Email checking and getting data from a file


GurusGuru
09-11-2004, 03:11 AM
I am using the following form to submit an enquiry/message:

<form name="form1" action="http://www.xyz.com/cgi-bin/mailer.pl" method="POST" onsubmit="return checkFields(this);">
<p><br>
Email<input name="email" size="40"><br><br>
Name<input name="name" size="40"><br><br>
Organization<input name="organization" size="40"><br><br>
Address<input name="address" size="40"><br><br>
City <input name="city" size="40"><br><br>
Country<input name="country" size="40"><br><br>
Message <textarea rows="4" name="Message" cols="30"></textarea><br><br>
<input type="submit" name="process_form" value="Submit Form">
<input type="reset" value="Clear Form"></p>
</form>

Can anyone develop a script that can do this:

1) As soon as someone fills his email, it checks to see if that email is present in a database file http://www.xyz.com/cgi-bin/dat.log (flat text separated by ::)(name::email::organization::address::city::country::)

2) If the email is present, then rest of the fields (Name, Organization, address, city, Country) except the message get automatically filled in from the data file http://www.xyz.com/cgi-bin/dat.log.

3) If that email is not present an alert box comes up with a message - "Email not found only registered members can send mail" and 2 buttons - 1)Try Again and 2) Register. When 'Try Again' button is clicked the alert box closes and the email field become empty. When 'Register' button is clicked, he is taken to a Registration Page - register.htm

CyCo
09-11-2004, 01:39 PM
Originally posted by GurusGuru
Can anyone develop a script that can do this:


Yes, it could be written, but IMHO it is a bad way to do it. Think about it. I'm sure anyone could eventually find an existing email that you have stored (and I don't mean their own). And when they do, you've just populated the form with private information. A better way to do this would be to have an existing member login. And after matching username and password with the data file, populate the textfields at that point.

Jona
09-11-2004, 02:03 PM
This works for me, unless there's something I did that you didn't want to do.


#!C:\Perl\bin\perl.exe

use strict;
use CGI qw(:cgi);
use CGI::Carp qw(fatalsToBrowser);

print header();

my $email = param('email');
my @info = ();

if($email eq ''){
print "Please fill in the email field properly.\n";
} else {
open(LOGFILE, "dat.log") || die("Cannot open log file: $!");
my @logData = <LOGFILE>;
foreach my $k (@logData){
if($k =~ /$email/){
@info = split("::", $k);
}
}
}

if(defined (@info)){
foreach my $key (@info){
print $key, "<br>";
}
} else {
print "Not found, so creating file...";
open(LOGNEW, ">>dat.log") || die("Cannot open log file: $!");
# flock(LOGNEW, 2); # Does not work on Windows
seek (LOGNEW, 0, 2);
my $temp = param('name'). "::". param('email'). "::". param('organization').
"::". param('address').
"::". param('city') . "::". param('country'). "\n";
print LOGNEW $temp or die("Cannot write to file: $!");
print "Printed data to logfile.";
undef $temp;
}

GurusGuru
09-12-2004, 03:00 AM
Thanks Jona. You'll have to explain step wise, as to how I should use the script. Less than novice in perl.

Jona
09-12-2004, 07:08 PM
If you're less than a novice you should take the time to learn it better before requesting scripts, or learn something easier such as PHP. Basically, use the form you posted, but set the action to "process.pl" and save the code I posted as process.pl in the same directory. You'll see the output then. Make sure that "data.log" is also in the same directory, otherwise the script won't find the file.

GurusGuru
09-13-2004, 08:26 AM
But how do I call/run the script from the form mentioned above which is created dynamically and contains the email ID of the recepient.

Jona
09-13-2004, 04:10 PM
Originally posted by GurusGuru
But how do I call/run the script from the form mentioned above which is created dynamically and contains the email ID of the recepient.

I don't understand.

GurusGuru
09-25-2004, 12:14 AM
1) As soon as someone fills his email (in the above form), it checks to see if that email is present in a database file http://www.xyz.com/cgi-bin/dat.log (flat text separated by :(name::email:rganization::address::city::coun
try:

2) If the email is present, then rest of the fields (Name, Organization, address, city, Country) except the message get automatically filled in from the data file http://www.xyz.com/cgi-bin/dat.log.

3) If that email is not present an alert box comes up with a message - "Email not found only registered members can send mail" and 2 buttons - 1)Try Again and 2) Register. When 'Try Again' button is clicked the alert box closes and the email field become empty. When 'Register' button is clicked, he is taken to a Registration Page - register.htm