Hi, all

sorry this post is kinda long.

I an new to libwww-perl, here i am having problem to
deal with a form submission involved javascript. I
don't know much about javascript.the form page is at
www.foo.com/submit

Here is the perl script i wrote. i keep getting an
error saying "you have to enable javascript...etc"

use LWP; # 5.64 installed
$ua = LWP::UserAgent->new();
$ua->agent("Mozilla/4.0");
$ua->cookie_jar({});

my $response =
$ua->post('http://www.foo.com/submit/stor.php3',
[ name => 'wow', email => [EMAIL PROTECTED]', url =>
'www.foo1.com', description => 'foo']
);
print $response->as_string;

Here is the form part.
######################
<form name=sf>
<table boder=1>
<tr><td><font size=1 >Your name :</td><td
valign=top><input name=n size=40></td></tr>
<tr><td><font size=1>Your E-mail address</td><td
valign=top><input name=e
size=40></td></tr>
<tr><td><font size=1 face=verdana>URL:</td><td><input
name=u size=40></td></tr>
<tr><td><font size=1>Subject:</td><td
valign=top><input name=d size=40></td></tr>
<tr><td valign=top><font size=1>Anything else to say?
;-):</td><td><textarea name=c cols=34
rows=5></textarea></td></tr>
<tr><td></td><td><input type=button value="Submit your
page" onClick="javascript:Submit();return
false;//"></td>
</table>
</form>
#################
I am not sure what type of form method should i
use,post or get? yet it doesn't invoke a script but a
JS onClick function. how to deal with js and perl
together...

Now the JS part
#################
<script src="vertical.js"></script>
<script src="horizontal.js"></script>

<script language="JavaScript">
<!--

function CookieSet( name, value, expire )
{
        if( document.cookie.length > 4000 )
                window.alert( "Your cookie is getting close to 4k"
);

        var expDate = new Date();
        expDate.setTime( expDate.getTime() + (expire != 0 ?
expire : 0 ) );
        document.cookie = name + "=" + escape( value ) + (
expire ? "; expires=" + expDate.toGMTString() + ";":
"") ;
}

function Submit()
{
        var name = document.sf.n.value;
        var email = document.sf.e.value;
        var url = document.sf.u.value;
        var description = document.sf.d.value;
        var message = document.sf.c.value;

        if( name.length == 0 || email.length == 0 ||
url.length == 0 )
        {
                alert( "Please fill out all neccessary fields!" );
                return false;
        }

        if( email.indexOf( "@" ) == -1 || email.indexOf( "."
) == -1 )
        {
                alert( "Your e-mail address seems to be invalid.
Please supply a valid e-mail address" );
                return false;
        }

        CookieSet( "name", name );
        CookieSet( "email", email );
        CookieSet( "url", url );
        CookieSet( "description", description );
        CookieSet( "message", message );
        CookieSet( "ref", document.location.href );

        self.document.location.href="stor.php3";

        return false;
}

//-->
</script>
#################
My guess: it uses cookie. at the end it direct data to
stor.php3. but i am not sure if the above js means
that it set cookie before calling stor.php3 file.

here is my questions. Can someone give me hint or
sample code to interact between perl and js. I have
been searching the net couldn't find more info.

if the cookie happens before calling stor.php3, then
what url should i get cookie from and carry it around
to stor.php3? sorry, i unsure how i ask this
question..

Thanks.

Qiang


__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

Reply via email to