dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: contact form

  1. #1
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    I have been working on this contact form for several hours, and it does not work, could someone please take a look at it and see if they can find what is wrong with it.
    Thanks

    http://www.geocities.com/norefunds3/contact.fla

  2. #2
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    this command isn't being satisfied.. success is never being set to 1

    if (success == "1") {
    gotoAndPlay ("output");
    } else {
    gotoAndPlay ("wait");
    }

  3. #3
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    do you know how I would fix that?

  4. #4
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    if ur cgi script is supposed to give the value of 1 then it isn't working.

    I would try d'l formmail http://www.scriptarchive.com/
    replace ur current script ur with the formmail.pl script. And don't forget to upload the .pl script using ASCII

  5. #5
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    im using the formmail script on mysite. http://www.digisoftdesign.com

  6. #6
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    i still don't understand how i would be able to set it up, what do I need to do to make the formmail thing work on my form, thanks

  7. #7
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    Here is what my cgi file says, maybee it will help


    #!/usr/bin/perl

    use CGI;

    # ----------------------------- define variables -----------------------------

    # @restrictTo is an array containing refering addresses to which you
    # wish to grant access to your script. If it contains a single value of
    # 'all' then any refering address can access your script.

    # uncomment the next line to grant access to only restricted addresses
    #@restrictTo = ('themakers.com', 'idgbooks.com');

    # comment the next line if you restrict access.
    @restrictTo = ('all');

    # $toEmail is the default email you wish this script to send all
    # emails to. uncomment the line below to do this.
    # $toEmail = 'user@yourdomain.com';

    # $sendMailProg is the location of the mail send program on your server.
    # the default setting will work for most Unix servers.

    $sendMailProg = '/usr/lib/sendmail';

    # ------------------------ end define variables ----------------------------------

    # -------------------------- call subroutines ------------------------------------

    # step 1: validate the refering address
    &validateReferer;

    #step 2: get data from form post
    &getData;

    #step 3: check the output request type
    &checkOutputRequest;

    #step 4: check required fields
    &checkRequired;

    #step 5: send email
    &sendEmail;

    # ----------------------- end call subroutines -----------------------------------

    # --------------------------- subroutines ----------------------------------------

    sub validateReferer
    {
    local $isValid = 0;

    # checks to make sure that the HTTP_REFERER has been passed
    if ($ENV{'HTTP_REFERER'})
    {
    # compares each address in the @restrictTo array to the refering address
    # if it finds a match, it flags $isValid to true and breaks out of the
    # foreach loop
    foreach $address (@restrictTo)
    {
    if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$address|i || $address eq 'all')
    {
    $isValid = 1;
    last;
    }
    }
    }
    # if HTTP_REFERER has not been passed, it checks to see if the value of the first
    # element of the restrictTo array is 'all', in which case all refering addresses
    # are granted access, so the $isValid is flagged true.
    elsif ($restrictTo[0] eq 'all')
    {
    $isValid = 1;
    }

    # if the refering address is not a valid on, output an error message.
    if ($isValid != 1)
    {
    &output('invalidAddress');
    }
    }

    sub getData
    {
    if ($ENV{'REQUEST_METHOD'} eq 'GET')
    {
    # split the query_string into an array that holds the name/value pairs.
    @variables = split(/&/, $ENV{'QUERY_STRING'});
    }
    elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
    {
    read(STDIN, $fromPost, $ENV{'CONTENT_LENGTH'});

    # split the previously assigned value of $fromPost into an array that
    # holds the name/value pairs.
    @variables = split(/&/, $fromPost);
    }

    # if no request method has been passed (no form information) then output
    # an error message.
    else
    {
    &error('noRequestMethod');
    }

    # break each name/value pair apart, convert them from the URLenceded format,
    # and place them into an associative array.
    $k = 0;
    foreach $variable (@variables)
    {

    local($varName, $varValue) = split(/=/, $variable);

    $varName =~ tr/+/ /;
    $varName =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    $varValue =~ tr/+/ /;
    $varValue =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    $varValue =~ s/<!--(.|\n)*-->//g;

    $FIELDS{$varName} = $varValue;

    $order[$k] = $varName;
    $k = $k + 1;
    }

    }

    sub checkOutputRequest
    {
    $outputEnvVars = 0;
    if (defined($FIELDS{'envVars'}))
    {
    if ($FIELDS{'envVars'} eq 'yes')
    {
    $outputEnvVars = 1;
    }
    if ($FIELDS{'envVars'} eq 'only')
    {
    &output('envVars');
    }
    }
    }

    sub checkRequired
    {
    # checks to see if a formfield called 'required' has been passed
    # if not, define @required to be empty. otherwise, define @required
    # to be the elements from the comma-delimited list passed from the form.
    if (!defined($FIELDS{'required'}))
    {
    @required = ();
    }
    else
    {
    @required = split(/,/,$FIELDS{'required'});
    }

    # in order to send an email it is necessary to have an address to
    # which to send. if no value was passed and a default has not been
    # specified within the script, then add to the array of missing
    # values.
    if (!defined($FIELDS{'to'}))
    {
    if (!defined($toEmail))
    {
    push(@missing, 'to');
    }
    }
    # if an email address has been passed frmo the form, then make sure that it
    # is a valid format for an email address. otherwise, output an error message.
    elsif ($FIELDS{'to'} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $FIELDS{'to'} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
    {
    &output('badEmail');
    }

    # check to make sure each required formfield has been passed.
    foreach $require (@required)
    {
    if (!defined($FIELDS{$require}))
    {
    push(@missing, $require);
    }
    }

    # if any missing formfields were detected, output the error message.
    if (defined(@missing))
    {
    &output('missingRequired');
    }
    }

    sub sendEmail
    {

    # begin sending the mail.
    open(MAILPROG, "|$sendMailProg -t");
    if (defined($FIELDS{'to'}))
    {
    print MAILPROG "To: $FIELDS{'to'}\n";
    }
    elsif (defined($toEmail))
    {
    print MAILPROG "To: $toEmail\n";
    }
    else
    {
    &output('badEmail');
    }

    if (defined($FIELDS{'from'}))
    {
    print MAILPROG "From: $FIELDS{'from'}\n";
    }
    else
    {
    print MAILPROG "From: <unknown>\n";
    }

    if (defined($FIELDS{'subject'}))
    {
    print MAILPROG "Subject: $FIELDS{'subject'}\n\n";
    }
    else
    {
    print MAILPROG "Subject: <none>\n\n";
    }

    # print each variable name and value to the body of the email.
    foreach $index (@order)
    #foreach $member (keys %FIELDS)
    {
    if ($index ne 'to' && $index ne 'from' && $index ne 'subject')
    # if ($member ne 'to' && $member ne 'from' && $member ne 'subject')
    {
    print MAILPROG "$index:\n\n$FIELDS{$index}\n\n";
    # print MAILPROG "$member:\n\n$FIELDS{$member}\n\n";
    }
    }

    # sends email.
    print MAILPROG ".";

    close (MAILPROG);



    # output the success of the send to the user.
    &output('sentEmail');

    }


    sub output
    {
    # create a local variable to hold the value of the paramaters
    # passed to the subroutine.
    local ($outputType) = @_;

    if ($outputType eq 'invalidAddress')
    {
    print "Content-type: text/plain\n\n";
    print "success=0&error=invalidAddress";
    exit;
    }

    elsif ($outputType eq 'noRequestMethod')
    {
    print "Content-type: text/plain\n\n";
    print "success=0&error=noRequestMethod";
    exit;
    }

    elsif ($outputType eq 'missingRequired')
    {
    # create local variable to hold length of array for
    # missing formfields.
    local $howManyMissing = scalar(@missing);
    print "Content-type: text/plain\n\n";
    print "success=0&error=missingRequired&missing=";

    # print a comma-delimited list of the missing formfields.
    for ($i=0; $i< $howManyMissing-1; $i++)
    {
    print "$missing[$i],";
    }
    print "$missing[$howManyMissing-1]";
    exit;
    }

    elsif ($outputType eq 'badEmail')
    {
    print "Content-type: text/plain\n\n";
    print "success=0&error=badEmail";
    exit;
    }

    elsif ($outputType eq 'envVars')
    {
    print "Content-type: text/plain\n\n";
    print &envVars;
    print "&timeDate=";
    print &makeDate;
    exit;
    }

    elsif ($outputType eq 'sentEmail')
    {
    print "Content-type: text/plain\n\n";
    print "success=1&timeDate=";
    print &makeDate;
    exit;
    }
    }

    sub makeDate {

    @days = ('Sunday','Monday','Tuesday','Wednesday',
    'Thursday','Friday','Saturday');
    @months = ('January','February','March','April','May','June' ,'July',
    'August','September','October','November','Decembe r');

    ($sec,$min,$hour,$dayOfMonth,$month,$year,$dayOfWe ek) = (localtime(time))[0,1,2,3,4,5,6];
    $time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
    $year += 1900;

    $date = "$days[$dayOfWeek] $dayOfMonth $months[$month] $year $time";
    $date = CGI::escape($date);

    return $date;
    }


    sub envVars
    {
    local $remoteHost = $ENV{'REMOTE_HOST'};
    local $httpReferer = $ENV{'HTTP_REFERER'};
    local $httpUserAgent = $ENV{'HTTP_USER_AGENT'};

    $remoteHost = CGI::escape($remoteHost);
    $httpReferer = CGI::escape($httpReferer);
    $httpUserAgent = CGI::escape($httpUserAgent);

    $envVars = "REMOTE_HOST=$remoteHost&HTTP_REFERER=$httpReferer &HTTP_USER_AGENT=$httpUserAgent";
    return $envVars;
    }
    # ----------------------------- end subroutines ------------------------------------



  8. #8
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    ill email you tomorrow with complete instructions.

    p.s. thanks for the contact form

    Below is the result of your feedback form. It was submitted by ( hfhf) on Thursday, August 8, 2002 at 18:01:40
    ---------------------------------------------------------------------------

    name: hhhh

    company: hfh

    url: hfh

    project: hfhh

    budget: hf

    state: fh

    zip: hfh

    country: hfh

    phone: hfh

    find_us?:

    ---------------------------------------------------------------------------

  9. #9
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    Do you think that you could send that now?

    Thanks

  10. #10
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    sorry dude, i was really busy today. Ill make a post it note and get back to ya tommorrow.

  11. #11
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    thats ok, thanks

  12. #12
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    Today?

  13. #13
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    get the script from http://www.scriptarchive.com/formmail.html
    ~ unzip it
    ~ upload the .pl script to your cgi-bin directory on your webserver (Using ASCII upload format)


    ~on the submit button for your form put the following code:
    on (release) {
    subject = "Contact Form";
    recipient = "email@yourdomain.com";
    loadVariablesNum ("http://domain.com/cgi-bin/formmail.pl", 0, "GET");
    //Goto the complete frame!
    _parent.gotoAndPlay();
    }
    }


    ~delete the code that says:

    if (success == 2) {
    }

    //the code mentioned above that wasn't being satisfied

    thats it, it should work now.

  14. #14
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    it's still not working, do I need to configure the cgi script itself?

  15. #15
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238

  16. #16
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    it wont let me view it

  17. #17
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    i am thinking that the text field needs a specific variable name, do you know what it should be?

  18. #18
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    could you post your cgi script, instead of a link, cause it wont let me view it

  19. #19
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    i can't legally show you the script. But you can d'l it @ http://www.scriptarchive.com/formmail.html

  20. #20
    Senior Member
    Join Date
    Jun 2002
    Posts
    127
    I already have downloaded it, but I need to know if you need to configure the cji script itself, because the form is not working. If you don't, then do you have to have a specific variable name for the one input text field that I have?


    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center