A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: how can i input information to a .txt file for an e-mail list

  1. #1
    Junior Member
    Join Date
    Dec 2002
    Posts
    21

    how can i input information to a .txt file for an e-mail list

    i have the options on my site for people to enter their e-mail to get on a mailing list. so i have an "input" text box for that, but how do i take that info and write/append it to a .txt file so that i actually have a list?

    any help is GREATLY appreciated. Thanks!

    rdawg125

    this is the site:

    http://djmcnasty.netfirms.com

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    you could use a server side scripting language to write the file, for example php, flash can send the email variable to this script. if you save a textfile (empty) on your server and name it email.txt (CHMOD it to 666, this should be possible from your FTP program) then assuming your host supprts PHP you can add another file, writefile.php
    which is written like this,

    Code:
    <?php
    
    if ($fp = fopen('email.txt', 'a')) { // open email.txt ready to append data
        $email = $HTTP_POST_VARS['email'] . ',';
        fwrite($fp, $email); // add the email to the file
        fclose($fp); // close the file
        $msg = urlencode('Thanks for adding your email address!');
        echo "&result=$msg"; // send something back to flash
    }  else {
        $msg = urlencode('Sorry, we were unable to add your email address to our list');
        echo "&result=$msg";
    }
    
    ?>
    next in flash create a movie clip, in this clip put an input textbox on frame 1, give this the variable name email. also place a button on the stage. give this button the actions,

    on (release) {
    this.loadVariables("writefile.php","POST");
    this.gotoAndStop(2);
    }

    in frame 2 put a message telling the user their address is being added and in frame 3 add a dynamic textbox with the variable name result (result is the variable being sent back by PHP to tell us if the script was successful). finally add a clip event to the movie clip,

    onClipEvent(load) {
    this.stop();
    }
    onClipEvent(data) {
    this.gotoAndStop(3);
    }

  3. #3
    Junior Member
    Join Date
    Dec 2002
    Posts
    21

    two things

    it doesnt seem to be working right..... because even when it the movie shows what text was supposedly put into the .txt, when i open the email.txt with notepad, it's still empty. also, im not sure where you meant for me to put this code:

    onClipEvent(load) {
    this.stop();
    }
    onClipEvent(data) {
    this.gotoAndStop(3);
    }

    i tried just putting it into actions for the 3rd frame, but i got 2 errors:

    Scene=Scene 1, Layer=Layer 1, Frame=3: Line 1: Clip events are permitted only for movie clip instances
    onClipEvent(load) {

    Scene=Scene 1, Layer=Layer 1, Frame=3: Line 4: Clip events are permitted only for movie clip instances
    onClipEvent(data) {

    hmmmmmm, sr if ive just overlooked something flash is still relatively new to me :/

  4. #4
    Junior Member
    Join Date
    Dec 2002
    Posts
    21

    actually

    actually, it doesnt even show the input text 'email' on the 3rd frame like i said before. my mistake. it displays $msg"; as the text that was inputed in the first frame. hmmm

  5. #5
    Junior Member
    Join Date
    Dec 2002
    Posts
    21

    another thing

    why is it that in the php file you make it a conditional (if...else if...)? There's no question that i want the text written to the file, and what is the variable $fp??? you start the php by saying "if $fp=...", but I dont even have a variable defined like that in my .fla

  6. #6
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    first of all PHP is a server side scripting language. you would have to upload the PHP file to a server that runs PHP4 for the script to do anything. (you need to use something outside of flash to write to a text file since flash can't do it on it's own) for testing purposes (especially if you think you may need to use PHP a lot) it may be a good idea to install a web server on your machine (eg Apache, available from http://www.apache.org ) and get a copy of PHP (again free) from http://www.php.net

    as for the errors. clip events (onClipEvent(load), data etc) shouldn't be attached to frames within a movie clip, they get attached to the movie clip itself. to do this exit the timeline of the clip, and right click on the instance of the movie clip itself and then select actions to add the clip event.

    in the php script,

    $fp = fopen('email.txt', 'a')

    makes PHP attempt to open the file, email.txt, the 'a' is an option the specifies the file should be opened ready to append text to it (there are other options for reading, writing over whatever is there etc) the result of this is assigned to a variable $fp, which can be used throughout the script when we need to work with the file.

    the if statement tests that the file was able to be opened successfully, if it was everything goes ahead and the email address should be added to the file. otherwise an error message is sent back to the movie.

  7. #7
    Junior Member
    Join Date
    Dec 2002
    Posts
    21

    okay

    ok, so i got the download from apache.org but i dont know how to install/use this program.... where do i put all the files? there's no exe file...hmmmmm

  8. #8
    Junior Member
    Join Date
    Dec 2002
    Posts
    21

    nm

    nm i got the right file now hehe, i gotta fiddle with this prog now

  9. #9
    Member
    Join Date
    Oct 2000
    Posts
    85
    I just tried this PHP script for the email submit, but it always comes back with "Sorry, we were unable to add your email address to our list" in the dynamic box on the third frame. Why would it reject an email submit???

  10. #10
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    check the file permissions for the text file you are trying to open, they should be set to 666.

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