PDA

Click to See Complete Forum and Search --> : How to fill the contents in Flash Form from CGI-Perl



Siraj
09-24-2000, 04:56 AM
Hi,
I have developed a form in flash with certain fields. How do I fill the values in these fields (variables) using Perl language. I know it can be done through Load variables using text files, through HTML using QueryString and through JavaScript. I read that it can be possible through server side scripting also like CGI-perl.
Can anybody help out how to set the values in Flash Form using Perl language.
Thanks in advance

Regards,
Siraj

sarabob
09-28-2000, 05:05 AM
Originally posted by Siraj
Hi,
I have developed a form in flash with certain fields. How do I fill the values in these fields (variables) using Perl language. I know it can be done through Load variables using text files, through HTML using QueryString and through JavaScript. I read that it can be possible through server side scripting also like CGI-perl.
Can anybody help out how to set the values in Flash Form using Perl language.
Thanks in advance

Regards,
Siraj

This is a forum on the swf file format, not a general server-side discussion. There is another forum on flashkit entirely dedicated to this topic at http://www.flashkit.com/board/forumdisplay.php?forumid=4

In answer to your question, try doing a loadVariables from a url such as http://yoursite.com/cgi-bin/yourscript.cgi. Your script would look something like:


#!/usr/bin/perl -w

use strict;
use CGI;
my $query = new CGI;

my $value = 'My Name';

# all sorts of code can go here

print $query->header;
print "name=$value&loaded=true";


Which would be equivalent to SetVariable("name" = "My Name")

Siraj
09-29-2000, 03:42 AM
Lots of thanks for your reply. Now it starts working with Load variable. Now I have taken two variables in Flash and given the name as name and dispval. Name variable will let the user to enter the text while dispval variable's property disable editing is checked.I want that user write anything in name variable and click on Button, value of this variable should submit to CGI and in CGI and value of name should be copied in dispval flash variable. Following is the script in Perl that I wrote and linked with flash button's Load variable method. But it is not working at all.


//// Test.cgi

#!/usr/bin/perl -w
use strict;
use CGI;
my $query = new CGI;
&parse_forml;

sub parse_form {
# Define the configuration associative array. #
%Config = ('name','');

# Determine the form's REQUEST_METHOD (GET or POST) and split the form #
# fields up into their name-value pairs. If the REQUEST_METHOD was #
# not GET or POST, send an error. #
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
# Split the name-value pairs
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);
}
else {
&error('request_method');
}

# For each name-value pair: #
foreach $pair (@pairs) {

# Split the pair up into individual variables. #
local($name, $value) = split(/=/, $pair);

# Decode the form encoding on the name and value variables. #
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# If they try to include server side includes, erase them, so they
# aren't a security risk if the html gets returned. Another
# security hole plugged up.
$value =~ s/<!--(.|\n)*-->//g;

# If the field name has been specified in the %Config array, it will #
# return a 1 for defined($Config{$name}}) and we should associate #
# this value with the appropriate configuration variable. If this #
# is not a configuration form field, put it into the associative #
# array %Form, appending the value with a ', ' if there is already a #
# value present. We also save the order of the form fields in the #
# @Field_Order array so we can use this order for the generic sort. #
if (defined($Config{$name})) {
$Config{$name} = $value;
}
else {
if ($Form{$name} && $value) {
$Form{$name} = "$Form{$name}, $value";
}
elsif ($value) {
push(@Field_Order,$name);
$Form{$name} = $value;
}
}
}
# all sorts of code can go here
print $query->header;
print "dispval=$config{'name'}&loaded=true";
}


Regards,
Siraj

sarabob
09-29-2000, 05:48 AM
Originally posted by Siraj
Lots of thanks for your reply. Now it starts working with Load variable. Now I have taken two variables in Flash and given the name as name and dispval. Name variable will let the user to enter the text while dispval variable's property disable editing is checked.I want that user write anything in name variable and click on Button, value of this variable should submit to CGI and in CGI and value of name should be copied in dispval flash variable. Following is the script in Perl that I wrote and linked with flash button's Load variable method. But it is not working at all.



Urgh.

That perl won't even run - the use strict directive means you have to be a little more disciplined in coding - I get about 30 compilation errors. You aren't using CGI.pm properly either. Do you have access to a development environment, or are you just uploading the script and hoping? Perl is available for Windows and Macs if you don't have an internal web server/unix environment.

I suggest reading up on Perl/CGI before trying to go any further - I think you're still in cut and paste mode, judging by your code snippet.

Dump the ENV stuff - CGI.pm does all that for you. Your script will look much neater and will be much easier to understand.
Prefix new variables with "my " so use strict won't complain (but not subsequent uses of the same variable). You can get variables from the CGI object by using something like "my $data = $query->param('data')" where data is the name of the form field you are passing.

Email me if you need more help, but I would strongly suggest trying to do it yourself first...

Hope this helps.

Siraj
09-30-2000, 07:07 AM
Hi Adams,
Lots of thanks for UR sugesstions. I have just start learing the Perl and I was assigned to do this kind of Project. Anyway I have done this by individual scalar variable in Perl after your tips. Now I want to do it by using associative array that will make the routine much easy to handle. We do not have Linux/Unix server at our developmet place. but I have installed ActivePerl at our NT server. Please let me know also how to compile at NT plateform to get all the errors at a time. Following is the
script that is not runnuing successfully with associative array :

## test.cgi

#!/usr/bin/perl -w
use strict;
use CGI;
my $query = new CGI;
#my $name = $query->param('name');
#my $dispname = $query->param('dispvalue');
my $pnames{'name'}=$query->param('name');
my $pnames{'dispvalue'}=$query->param('dispvalue');
print $query->header;
while(($key,$value) each %pnames){
print "$key=$value&loaded=true";
}
#print "@pnames&loaded=true";
#print "dispval=$value&loaded=true";



Regards,
Siraj

sarabob
10-02-2000, 04:48 AM
Originally posted by Siraj
Hi Adam,

...snip...

Please let me know also how to compile at NT plateform to get all the errors at a time. Following is the
script that is not runnuing successfully with associative array :

## test.cgi

#!/usr/bin/perl -w
use strict;
use CGI;
my $query = new CGI;
#my $name = $query->param('name');
#my $dispname = $query->param('dispvalue');
my $pnames{'name'}=$query->param('name');
my $pnames{'dispvalue'}=$query->param('dispvalue');
print $query->header;
while(($key,$value) each %pnames){
print "$key=$value&loaded=true"
}
#print "@pnames&loaded=true"
#print "dispval=$value&loaded=true"


Try running the script on the command line. Open up a cmd/dos box and just type "perl myscript.pl". You can leave the shebang (#!) line at the top of the script so it will work when you upload it to a unix server. Alternatively, you could install BeOS ( http://free.be.com ) which has a much nicer interface than Linux but can still run perl in a unixey way, with Apache as a web server and a bash shell for development.

>perl ./test.pl
Can't declare hash elem in my at ./test.pl line 7, near "}="
"my" variable %pnames masks earlier declaration in same scope at ./test.pl line 8.
Global symbol "$key" requires explicit package name at ./test.pl line 10.
Global symbol "$value" requires explicit package name at ./test.pl line 10.
syntax error at ./test.pl line 10, near ") each"
Execution of ./test.pl aborted due to compilation errors.

You need to be able to run perl properly in a dev environment before you try to go any further. Randomly stabbing in the dark isn't going to get you anywhere - you're getting basic syntax errors here.

sarabob
10-02-2000, 05:27 AM
Try this:

-----

#!/usr/bin/perl -w
use strict;
use CGI;

my $query = new CGI;
print $query->header;
my %pnames; # hash of cgi params we need
my @out; # list of output name/variable pairs

$pnames{'name'} = $query->param('name');
$pnames{'dispvalue'} = $query->param('dispvalue');


while (my ($key,$value) = each %pnames){
push @out, "$key=$value";
}

# loaded=true allows flash4 to know we've finished the
# LoadVariables call. Set loaded=false, do loadvariables,
# then sit in a loop until loaded=true. That way you know
# that the cgi call has finished and your variables are available.
push @out, 'loaded=true';

my $outstring = join '&', @out;
print $outstring;

----

1. This way you only get one instance of loaded=true (the @out thing)
2. You'll need to catch errors - if name is not sent then things will break.
3. It isn't nice perl, but I'm trying to make it easier to understand...