dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Help need to amend contact form

  1. #1
    Member
    Join Date
    Jul 2005
    Posts
    83

    Help need to amend contact form

    Hi there,

    I'm wondering if anyone can help me to amend a contact form. Basically I've been re-using a form for a while now - a simple 3 variable form for name, email and message. I now need the user to select the subject from a drop down menu (2 options - "booking" and "general enquiry". I've also added a date chooser component, and I would like this date to be added to the information which is emailed on.

    I'm not sure whether the AS and PHP I'm using is easily amendable. Here's what I have:-

    The PHP code:-
    <?
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    $from = 'From: '.$_POST['name']." <".$_POST['email'].">";
    $to = "email@email.com";

    /* and now mail it */
    $mail_success = mail($to, $subject, $message, $from);
    if ($mail_success == true) {
    echo '&successvar=1&';
    } else {
    echo '&successvar=0&';
    }
    ?>



    The AS:-

    // create an instance of LoadVars to control communication with
    // the serverside script
    _lv = new LoadVars();

    // define what that instance should do when the successvar variable is
    // received from the serverside script
    _lv.onLoad = function() {
    if (Number(this.successvar)) {
    response_txt.text = "Thanks -- your message has been sent. We will contact you shortly.";
    } else {
    response_txt.text = "Sorry, there was a problem sending your message. Please try again";
    }
    };

    // show the cursor in the subject field when the form is displayed
    Selection.setFocus("name_txt");

    // set the tab order
    name_txt.tabIndex = 1;
    email_txt.tabIndex = 2;
    subject_txt.tabIndex = 3;
    message_txt.tabIndex = 4;

    // function that checks to see if the user has entered a name, an email
    // address (non blank, includes @), and a message. If any are missing,
    // show an error message. Otherwise, use _lv to call sendemail.php to
    // send the email.
    function sendmail() {
    response_txt.text = 'Please ensure all required fields have been filled in & try again';
    var ok = true;


    // change the default subject to something else if you want
    if (subject_txt.text == '') _lv.subject = "Website enquiry ";
    else _lv.subject = subject_txt.text;

    // is the name field blank?
    if (name_txt.text == '') {
    response_txt.text = "Please enter your name";
    ok = false;
    } else {
    _lv.name = name_txt.text;

    // is the email field blank or not have a "@"?
    if (email_txt.text == '' || email_txt.text.indexOf('@') == -1) {
    response_txt.text = "Please enter your email address";
    ok = false;
    } else {
    _lv.email = email_txt.text;




    // is the message field blank?
    if (message_txt.text == '') {
    response_txt.text = "You haven't typed in a message";
    ok = false;
    } else _lv.message = message_txt.text;
    }
    }

    // send the message
    if (ok) {
    response_txt.text = "Sending...";
    // this assumes the sendemail.php script exists in the same
    // directory as the swf, on a web server on which PHP is supported
    _lv.sendAndLoad("sendemail.php", _lv, "POST");
    }
    };


    I've had a look through the forums and various tutorials but I'm a little stuck on this one.

    Ideally I would like the date to be incorporated into the message body if at all possible.

    Any assistance much appreciated.

    Thanks in advance.

    Q.

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    the rest of this is ok for you and you just want the date in the body of the email correct?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Member
    Join Date
    Jul 2005
    Posts
    83
    Hi Kortex,

    Yes, I'd like the date to be incorporated into the body of the message, perhaps preceding the "message" and in the form Wedding Date: ["date"] if at all possible.

    Cheers,

    Q.

  4. #4
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    What format do you want the date in Mont Day Year? e.g., 1/15/2008 And let me clarify, is this the current date, or is this a date the user is supposed to be selecting?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  5. #5
    Member
    Join Date
    Jul 2005
    Posts
    83
    That date format is fine day/month/year. It relates to the date which is selected (ie a future date) using the date selector component.

    Thanks a million.

    Q.

  6. #6
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    ok thats a bit more complex as the current date is directly accessible from PHP.

    basically you are going to have to create a var on you loadVars object that = the selected date from the date chooser that and then reference that var in the PHP the same way you do the others. You may have to conver the date qto milliseconds.

    Then you are going to use the functions found here
    http://us3.php.net/manual/en/function.date.php

    to put it at the beginning of the message it will be something like

    $message = 'Wedding date: '. date('m/j/Y', $_POST['wedding_date'] .' '. $_POST['message'];
    Last edited by kortex; 01-15-2008 at 06:40 PM.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  7. #7
    Member
    Join Date
    Jul 2005
    Posts
    83
    Thanks so much for your help Jeremy. I really appreciate it. I'll give it a go and see how I get on.

    Cheers,

    Q.

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