The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 2 of 2

Thread: Validation of textfields

  1. #1

    Validation of textfields

    Hi,

    I created (adjusted) a mail form to send input textfields from flash to my email address. Everything works fine. The next step for me would be to ensure that people fill out all textfields before they are able to submit the form. At the moment it just sends the form whether somebody filled in the fields or not. Here is the as script:

    function clicked() {
    var lv = new LoadVars();
    lv.choose = choose.value;
    lv.employment = employment.value;
    lv.filmdatum = filmdatum.text;
    lv.kartenanzahl = kartenanzahl.value;
    lv.verpflegungbb = "";
    for(i=0; i<verpflegung.selectedIndices.length;i++) {
    lv.verpflegungbb += verpflegung.getItemAt(verpflegung.selectedIndices[i]).label + ", ";
    }
    //lv.verpflegung = verpflegung.selectedItems;
    //lv.ermaessigung = ermaessigung.value;
    lv.name = name.text;
    lv.tel = tel.text;
    lv.email = email.text;
    lv.message = message.text;
    //lv.email = email.text;
    //lv.organisation = organisation.text;
    //lv.additional = additional.text;
    //lv.profession = profession.text;
    //lv.newsLetter = newsLetter.text;
    //lv.project = project.text;
    lv.sendAndLoad("contactEon.php", lv, "POST");
    gotoAndStop("reg");
    }

    submit.addEventListener("click", clicked);

    and here the php script:

    <?
    $empfaenger = "info.embrace.online@gmail.com";
    $betreff = "New message from EON website";
    $from = "From: Embrace contact form <>";
    //$txt = "Project: ".utf8_decode($_POST['filmtitel'])."\n";
    //$txt .= "Project start: ".utf8_decode($_POST['filmdatum'])."\n";
    //$txt .= "Project participants ".utf8_decode($_POST['kartenanzahl'])." people \n";
    //$txt .= "Zu essen bitte: ".utf8_decode($_POST['verpflegungbb'])."\n";
    //if(utf8_decode($_POST['ermaessigung'])=="true") {
    //$txt .= "Eine ermäßigte Karte bitte \n";
    //}
    //$txt .= "Company name: \n".utf8_decode($_POST['company'])."\n";
    //$txt .= "Street: \n".utf8_decode($_POST['street'])."\n";
    //$txt .= "town: \n".utf8_decode($_POST['town'])."\n";
    //$txt .= "Tel: \n".utf8_decode($_POST['tel'])."\n";
    //$txt .= "email: \n".utf8_decode($_POST['email'])."\n";
    //$txt .= "organisation: \n".utf8_decode($_POST['organisation'])."\n";
    $txt .= "name: \n".utf8_decode($_POST['name'])."\n";
    $txt .= "tel: \n".utf8_decode($_POST['tel'])."\n";
    $txt .= "email: \n".utf8_decode($_POST['email'])."\n";
    $txt .= "message: \n".utf8_decode($_POST['message'])."\n";
    mail($empfaenger, $betreff, $txt, $from);
    ?>

    Works fine by the way if you are looking for a mail solotion with flash 8...

    Cheers Snowman...

  2. #2
    if haven't tested this, but it should work. there might be syntax errors:
    PHP Code:
    /*
    required form fields are in array keys.
    keep array values at zero.
    add fields as needed, but keep the format
    */
    $required_fields = array(
                            
    'tel'        => 0,
                            
    'email'        => 0,
                            
    'message'    => 0
                            
    );
                            
    /* will hold values in utf8_decode format */
    $utf8_post = array();                        

    /* loop through POST variables */
    foreach( $_POST as $key=>$val ) {
        
        
    /* apply utf8_decode to all values */
        
    $val utf8_decode$val );
        
        
    /* check if field was filled out */
        
    if( $val != '' ) {
            
    $required_fields[$key]++;
        }
        
        
    /* put values into utf8 array */
        
    $utf8_post[$key] = $val;
    }

    /* set error message to blank string initially */
    $error_message '';

    /* loop through required fields and see which still have 0 values */
    foreach( $required_fields as $key=>$val ) {
        if( 
    $val==) {
            
    $error_message .= $key.'|';
        }
    }

    /* check if error message has been appended */
    if( $error_message == '' ) {
        
        
    /* make our text string */
        
    $txt '';
        
    $txt .= 'name: '.$utf8_decode['name']."\n";
        
    $txt .= 'tel: '.$utf8_decode['tel']."\n";
        
    $txt .= 'email: '.$utf8_decode['email']."\n";
        
    $txt .= 'organisation: '.$utf8_decode['organisation']."\n";
        
        
    /* mail headers */
        
    $empfaenger 'info.embrace.online@gmail.com';
        
    $betreff 'New message from EON website';
        
    $from 'From: Embrace contact form <>';
        
        
    /* if no errors, try to mail */
        
    if( mail$empfaenger$betreff$txt$from ) ) {
            
    $output 'success';
        }
        else {
            
    $output 'error sending';
        }
    }
    else {
        
    $output 'errors&errors='.$error_message;
    }

    /* output that flash will read */
    echo 'msg='.$output;

    /*
    if validation errors, will output in this format:
    msg=errors&errors=tel|email
    ^ if tel and email were required, but left blank

    if mail fails, will output in this format:
    msg=error sending

    if successful, will output in this format:
    msg=success

    */ 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012