dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: how to create an if statement to check a form...

  1. #1

    resolved

    I have a form that works fine. The button to send the info has a script that looks like this:

    on (release) {
    if (!Email.length || Email.indexOf("@") == -1 || Email.indexOf(".") == -1) {
    EmailStatus = "Please enter a valid E-mail address";
    } else if (!realname.length) {
    EmailStatus = "Please Enter your name before Sending";
    } else if (!ContPhone.length) {
    EmailStatus = "Please enter your Phone Number";
    } else {
    loadVariablesNum ("http://www.mysite.com/cgi-bin/FormMail.pl", "0", "POST");
    EmailStatus = "Your info has been sent...Thank You!";
    }
    }
    on (release) {
    realname = "";
    BizAddy = "";
    ProjectTitle = "";
    ContPhone = "";
    Email = "";
    Additional = "";
    }
    This works fine, but there is one problem. If one of the required fields isn't filled out, it doesn't send the form (that's not the problem. The second part of the form is the problem. It blanks the form when the button is pressed. Of course if one of the required fields is blank they must start all over again. I need to write an if statement that says if the form is filled out blank the fields on button press, but if the form is missing a reqired field, don't blank the fields until they are filled out and the button is pressed again. My actionScripting is poor, but as I understand it it should go something like:

    If (realname and contphone and Email = "*") then ""
    else
    nothing
    that's the layman deal anyway...could someone that speaks the language better help me out?
    I would greatly appreciate any help I can get!
    Thanks in advance!
    -Potus


  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    184
    Your problem is this last chunk of code...

    on (release) {
    realname = "";
    BizAddy = "";
    ProjectTitle = "";
    ContPhone = "";
    Email = "";
    Additional = "";
    }

    ...which is actually telling Flash to clear the fields. Removing it should solve the problem.

  3. #3
    1. You don't need second on (release) part on button. That's what clears your form.

    2. EmailStatus = "Your info has been sent..." should not be part of your button. It should be part of FormMail.pl. Somewhere on the end of the script within print content

    print "Content-type: text/plain\n\n";
    print "EmailStatus=Your info has been sent... ";

    that's going to be returned to your flash form.

    3. if you want to clear your fields after the form is submitted you can place looping MC (two frames) with this code on one of the frames
    if (EmailStatus=="Your info has been sent...") {
    realname = "";
    BizAddy = "";
    ProjectTitle = "";
    ContPhone = "";
    Email = "";
    Additional = "";
    }

  4. #4
    Thankyou Dudo and Mr. Boris for answering

    Dudo your method is the one I was looking for but for some reason I cannot make my formmail.pl return the desired message to the EmailStatus. Perhaps this is because my form isn't on the main timeline, but actually resides in a movie clip. I used a bare bones CGI script that was posted with a tutorial (where I got the button script) but I wanted more security features so I changed to Matt's script Archive formmail. Here is the code at the bottom of the original formmail

    print "Content-type: text/html\n\n";
    print "_root.Mail.EmailStatus=Complete - Your mail has been sent";

    sub ErrorMessage {
    print "Content-type: text/html\n\n";
    print "_root.Mail.EmailStatus=Connection Failed Please Check the path to the Mail program";
    exit; }


    the line
    _root.Mail.EmailStatus=
    I thought my be the problem, is this what needs to be targeted to where the form resides on the main timeline?

    Thanks for the help you already provided...whatever else you can provide will inevitably return to you in the form of good karma!
    Thanks,
    Potus

  5. #5
    Try it without _root.Mail part. Just
    print "EmailStatus=blah... blah... ";

    But it should work either way.
    If it doesn't work this way, send your files and i'll take a look (dudovcic@simplexiti.com) zip it

    Regards

  6. #6
    will do...I should know something later today...thanks for your help and dedication...I hope to one day reach a decent level with this stuff!

    -Potus

  7. #7
    dudo,

    I posted a new question to the board. I also tried your idea of changing the _root.Mail.EmailStatus to just EmailStatus. in my test movie this kept the Emailstatus field from receiving anything at all from the CGI. The problem has to be the path to where the form resides. I'm boggled, but until I receive a message from the CGI, I cannot implement your script to blank all the fields...GRRRRR, well if at first you don't succeed....
    -Potus

  8. #8
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    may I comment on Matt's script here: its "security features" are made for html, they are worthless for flash use.
    formmail usually checks the referer, and some poor souls who only have formmail (i.e. who do not have a cgi-bin of their own) have found that their providers changed it to _require_ a referer. I have even seen one that was changed to read the form (it was using the referer to find it) and make sure that the recipient address occurs somewhere within the form. Of course, this version would not red the actionscript inside a movie and thus deny access.
    Now the most common browser these days does not send a referer at all with requests from the flash plugin, so the feature is either useless (standard code) or damaging (modified version). On the other hand, if someone is determined to annoy the world with spam, they probably know how to send the right referer... it is not really hard.
    If you want to contribute in the fight against spam, make sure that the recipient is set in the script rather than in the form. If you need multiple recipients, try to use something like a select box and send only the index (so the actual address again is in the script)
    This is possible with formmail too, if it is installed into a private cgi-bin. Only those shared versions really require that the recipient is set in the form

    Musicman

  9. #9
    Musicman is right. In order to make it work you would have to rewrite half of it (or more). I use much nicer script if you still interested. It's less than 3K(formmail 30K). It's very easy to set.

    be back Tuesday.
    Regards

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