• home
  • forum
  • my
  • kt
  • download
  • Home / 2D Graphics / Flash / Backend /

    Using CGI Forms in Flash

    Author: 2007-06-11 22:32:09 From:

    Introduction

    For those of us who don¡¯t have the pleasure of being able to use ASP or PHP on our web sites and are stuck using CGI, trying to achieve the same sorts of scripting that other lucky people are able to do seemed almost impossible! But it¡¯s not! This tutorial will show you how to use a CGI script that not only sends the form information but returns information back to the Flash 4 movie instead of sending the user to an html page. This tutorial requires that you have a fair understanding of CGI script editing and that you can get a script running, and make relevant changes to suit your needs. You must obviously be able to create a Flash 4 form.

    I will be using Matts Scripts Formmail as I¡¯m sure most of you have used it at some point in time. It requires that a few changes need to be made in the script. Basically it involves changing the script to send back plain text in the format that Flash can use to load variables, rather than returning back html code.

    The Script

    We¡¯re going to edit the sub return_html part of the script first.

    sub return_html {
     # Local variables used in this subroutine initialized. #
     #local($key,$sort_order,$sorted_field);
     # If redirect option is used, print the redirectional location header. #
     #if ($Config{'redirect'})
     #{
     # print "Location: $Config{'redirect'}\n\n";
     #}
     # Otherwise, begin printing the response page.                           #
     #else
     #{
     # Print HTTP header and opening HTML tags.                           #
     print "Content-type: text/html\n\n";
     # print "$#60;html$#62;\n $#60;head$#62;\n";
     # Print out title of page                                            #
     # if ($Config{'title'}) { print "  $#60;title$#62;$Config{'title'}$#60;/title$#62;\n" }
     # else                  { print "  $#60;title$#62;Thank You$#60;/title$#62;\n"        }
     # print " $#60;/head$#62;\n $#60;body";
     # Get Body Tag Attributes                                            #
     # &body_attributes;
     # Close Body Tag                                                     #
     # print "$#62;\n  $#60;center$#62;\n";
     # Print custom or generic title.                                     #
     # if ($Config{'title'}) { print "   $#60;h1$#62;$Config{'title'}$#60;/h1$#62;\n" }
     # else { print "   $#60;h1$#62;Thank You For Filling Out This Form$#60;/h1$#62;\n" }
     # print "$#60;/center$#62;\n";
     print "response=Below is what you submitted to $Config{'recipient'} on ";
     print "$date";
     # Sort alphabetically if specified:                                  #
     # if ($Config{'sort'} eq 'alphabetic') {
     #  foreach $field (sort keys %Form) {
     # If the field has a value or the print blank fields option  #
     # is turned on, print out the form field and value.          #
     #   if ($Config{'print_blank_fields'} || $Form{$field}) {
     #    print "$field: $Form{$field}\n";
     #   }
     #  }
     # }
     # If a sort order is specified, sort the form fields based on that.  #
     # elsif ($Config{'sort'} =~ /^order:.*,.*/) {
     # Set the temporary $sort_order variable to the sorting order,   #
     # remove extraneous line breaks and spaces, remove the order:    #
     # directive and split the sort fields into an array.             #
     #  $sort_order = $Config{'sort'};
     #  $sort_order =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
     #  $sort_order =~ s/(\s+)?\n+(\s+)?//g;
     #  $sort_order =~ s/order://;
     #  @sorted_fields = split(/,/, $sort_order);
     # For each sorted field, if it has a value or the print blank    #
     # fields option is turned on print the form field and value.     #
     #  foreach $sorted_field (@sorted_fields) {
     #   if ($Config{'print_blank_fields'} || $Form{$sorted_field}) {
     #    print "$sorted_field: $Form{$sorted_field}\n";
     #   }
     #  }
     # }
     # Otherwise, default to the order in which the fields were sent.     #
     # else {
     # For each form field, if it has a value or the print blank      #
     # fields option is turned on print the form field and value.     #
     #  foreach $field (@Field_Order) {
     #   if ($Config{'print_blank_fields'} || $Form{$field}) {
     #    print "$field: $Form{$field}\n";
     #   }
     #  }
     # }
     # print "$#60;p$#62;$#60;hr size=1 width=75%$#62;$#60;p$#62;\n";
     # Check for a Return Link and print one if found.                    #
     # if ($Config{'return_link_url'} && $Config{'return_link_title'}) {
     # print "$#60;ul$#62;\n";
     # print "$#60;li$#62;$#60;a #href=\"$Config{'return_link_url'}\"$#62;$Config{'return_link_title'}$#60;/a$#62;\n";
     # print "$#60;/ul$#62;\n";}
     # Print the page footer.                                             #
     # print $#60;$#60;"(END HTML FOOTER)";
     # $#60;hr size=1 width=75%$#62;$#60;p$#62;
     # $#60;center$#62;$#60;font size=-1$#62;$#60;a #href="http://www.worldwidemart.com/scripts/formmail.shtml"$#62;FormMail$#60;/a$#62; V1.6 © #1995 -1997  Matt Wright$#60;br$#62;
     # A Free Product of $#60;a href="http://www.worldwidemart.com/scripts/"$#62;Matt's Script #Archive, Inc.$#60;/a$#62;$#60;/font$#62;$#60;/center$#62;
     # $#60;/body$#62;
     # $#60;/html$#62;
     # (END HTML FOOTER)
     #}
    }
    The Changes NeededYou will see that basically what has been done is any PRINT statement with html in it has either been removed or had it¡¯s html code removed from it. Also notice that the first PRINT statement that hasn¡¯t been commented out has ¡°response=¡± at the beginning. This is the format that Flash 4 requires variables to be in. Other areas of the script that would need to be changed are the ERROR HTML areas. If you understood the above then these areas should be fairly straightforward to change yourself. Just remove all the html from them, and insert ¡°response=¡± into the first line, then the error message. You may wish to insert a Flash button on the sent page so that the user can return to the Flash form if there is an error.

    The Flash Movie

    Onto the Flash movie itself...

    Create your Flash form just as you would create it in HTML with the relevant requirements of Set Variables for Formmails hidden variables.

    Note: Remember not to put ¡®redirect¡¯ or any of the body attributes). The only necessary variable you need to set it ¡®recipient¡¯ which you set to your email address to receive the message.

    Obviously you can set some extra variables if you want, but only ones which don¡¯t affect the variables the script returns at this point.

    The Flash Movie (cont)

    Create a button on the form with On Release Set Variable: ¡°response¡± = ¡°Sending Message¡±. Then set Load Variables with the URL of the formmail.pl script. Set send using Get or Post (formmail will work with either).

    This is where other methods which use Get URL rather than Load Variables fail to send messages from the CGI script back to the Flash form. (Some of you may have also noticed that IE5 forces the URL to whatever URL you set in Get URL, rather than the scripts returned HTML.)

    The Final Touches

    Create a blank keyframe say 5 frames after your form. In this frames insert a text field to receive the message back from the script. Set the name of it to ¡°response¡± and the parameters below.

    That¡¯s it! Now when a user sends a message via your Flash form, it can now send the message as well as inform the user that it has been sent and what exactly they sent to you. This method can be used with many other CGI applications such as chat rooms, whois queries and anything else you can think of where a CGI script returns back html. You just need to edit the script slightly to return the Text Field Properties name= the message.

    Good Luck and happy flashing!
    Eng Wei Chua

    » Level Advanced

    Added: : 2000-05-02
    Rating: 7.00 Votes: 158
    Hits: 19143
    » Author
    Eng Wei Chua
    » Download
    Download the files used in this tutorial.
    Download (51 kb)

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      3D (20)
      Math Physics (14)
      3rd Party (5)
      Navigation (60)
      Actionscripting (26)
      Optimization (16)
      Animation (32)
      Projector (9)
      Audio (46)
      Special Effects (112)
      Backend (25)
      Text Effects (65)
      Drawing (18)
      Tips and Techniques (41)
      Dynamic Content (25)
      Tricks (6)
      Games (66)
      Utilities (19)
      Getting Started (71)
      Video (10)
      Interactivity (21)
      Web Design (22)

    New

    Hot