Gossamer Forum
Home : General : Perl Programming :

weird problem on form get and post method as well as Links::init_user()

Quote Reply
weird problem on form get and post method as well as Links::init_user()
  


Hi seniors.

i have a weird problem haunting me for weeks


everrything runs well when i use get method to fetch the from data . while it meet two problems when i try to change form method to "post"

1. i have to uncomment #Links::init_user(); or it will show you timeout
2. after uncomment #Links::init_user(); it runs ok while produce timeout again when i try to run a sub routine.

Could you one light me a bit what is the exact problem i have. as i have try to fix it for weeks in vain.



here is scirpts test.cgi

#!/usr/bin/perl
### cookie content. you could copy it to the cookie## $D = {_SESSION_ID => '3d1cef209379994ec50edca13cdd37a6',_SESSION_ATIME => 1247471428,CART => [{name => 'product3name',quantity => 1,price => 33,itemID => '1003',prod_subtotal => 33}],_SESSION_REMOTE_ADDR => '127.0.0.1',_SESSION_EXPIRE_LIST => {},_SESSION_CTIME => 1247471352};
use CGI::Session;
use Data::Dumper;
use CGI;
use lib 'D:\webtest\merchant\linkcart\admin';
use Links qw/:objects/; # or whatever $IN, $DB, $CFG, $USER etc...
use Links qw/$USER/;
Links::init('D:\webtest\links\admin'); #########################
#Links::init_user(); # gets the user information
use Links::SiteHTML; # if your using templates

############
my $cgi = new CGI;
my $session = new CGI::Session(undef, $cgi, {Directory=>'c:/tmp/carttmp'});
#### change the directory as per needs
print $session->header();
############
my $itemIDnum = $cgi->param('itemIDnum') || 1;
my $itemID = $cgi->param('itemID') || 1;
my $name = $cgi->param('name') || 1;
my $price = $cgi->param('price') || 1;
my $quantity = $cgi->param('quantity') || 1;
my $cmd = $cgi->param('cmd') || 1;

if ( $cmd eq "display" ) {
print display_cart($cgi, $session);
} elsif ( $cmd eq "add" ) {
# print add_item($cgi, $session, \%products,);

#print " Oops! Error<br><br>$cmd<br>$name $itemIDnum $price $quantity <br>\n";
print display_cart($cgi, $session);
# print " testtesttest<br><br>$cmd<br>$name $itemIDnum $price $quantity <br>\n";
} elsif ( $cmd eq "remove") {
print remove_item($cgi, $session);
} elsif ( $cmd eq "clear" ) {
print clear_cart($cgi, $session);

} elsif ( $cmd eq "update" ) {
print update_cart($cgi, $session);
} else {
print display_cart($cgi, $session);
}

sub display_cart {

my ($cgi, $session,$product,$tags) = @_;
# getting the cart's contents
my $tags;
$tags->{total_price} = 0;
foreach my $product ( @{$session->param('CART')} ) {
$product->{prod_subtotal} = $product->{price} * $product->{quantity};
$tags->{total_price} += $product->{prod_subtotal};
$tags->{itemmaxtemp}=$itemmaxtemp;
$tags->{itemID}=$itemID;
push @{$tags->{cart_loop}}, $product;
}

print $cgi->header();
print Links::SiteHTML::display('8gtcart', $tags);
exit;
}



below are form i used to test it

###### it runs well when using get method. while it pruduce timeout when using post method , how to correct it?????
<FORM METHOD=get ACTION="test.cgi">
<input type="hidden" name="itemID" value="21">
<input type="hidden" name="name" value="ddd3">
<input type="hidden" name="cmd" value="add">
<BR><INPUT type="submit" value="Order Now">
</FORM>
<input type="hidden" name="itemID" value="21">
<input type="hidden" name="name" value="ddd3">
<input type="hidden" name="price" value="21">
<input type="hidden" name="cmd" value="add">
Quote Reply
Re: [courierb] weird problem on form get and post method as well as Links::init_user() In reply to
here is the tempalate 8gtcart.html


<%-- cart start here --%>
<%if cart_loop%>
Here are your cart: <br> <br><br>
<%if itemmaxtemp%><h2>Oops! Error</h2> <font color="maroon">* Oops! Error! max <%itemmaxtemp%> items only , <%itemID%> was not added into the cart. <br> please delete one itme from the cart first</font><br> <br><%endif%>

<form action="cart.cgi" method="get">
<table>
<tr>
<td><font size="2"> Product ID </font> </td>
<td><font size="2"> Product </font> </td>
<td><font size="2">Unit Price </font> </td>
<td><font size="2"> Qty </font> </td>
<td><font size="2"> Subtotal </font> </td>
</tr>
<%loop cart_loop%>
<tr>
<td><font size="2"><%itemID%></font> </td>
<td><font size="2"><%name%></font> </td>
<td><font size="2"><%price%></font> </td>
<td><input type="text" name="quantity" size="1" value="<%quantity%>"><a href="http://homeip.org/link/linktest/cart.cgi?cmd=remove;itemID=<%itemID%>"><font size="1"> X</font></a></td>
<td><font size="2"><%prod_subtotal%></font> </td>
</tr>
<INPUT TYPE="hidden" NAME="itemID" value="<%itemID%>"><INPUT TYPE="hidden" NAME="name" value="<%name%>"><INPUT TYPE="hidden" NAME="price" value="<%price%>">
<%endloop%>
</div>
<tr>
<td colspan="3">Sub Total</td><td><%total_price%></td>
</tr>
</table>
<INPUT TYPE="hidden" NAME="cmd" value="update">
<br><br><br>
<input type=submit value="update quantity"> <input type=reset value="reset" ></form>
<%else%>
<p>There are no items in your cart yet</p>
<%endif%>
<%-- cart end --%>
<BR><BR><BR>
<a href="http://homeip.org/link/linktest/cart.cgi?cmd=add;itemID=1001;name=product1name;price=11">+1001</a> <BR><BR>
<a href="http://homeip.org/link/linktest/cart.cgi?cmd=add;itemID=1002;name=product2name;price=22">+1002</a> <BR><BR>
<a href="http://homeip.org/link/linktest/cart.cgi?cmd=add;itemID=1003;name=product3name;price=33">+1003</a> <BR><BR>
<a href="http://homeip.org/link/linktest/cart.cgi?cmd=add;itemID=1004;name=product4name;price=44">+1004</a> <BR><BR>
<a href="http://homeip.org/link/linktest/cart.cgi?cmd=add;itemID=1005;name=product5name;price=55">+1005</a> <BR><BR>
<a href="http://homeip.org/link/linktest/cart.cgi?cmd=update">multiple update cart</a> <BR><BR>

<a href="http://homeip.org/link/linktest/cart.cgi?cmd=remove;itemID=1001">-1001</a> <BR><BR>
<a href="http://homeip.org/link/linktest/cart.cgi?cmd=remove;itemID=1002">-1002</a> <BR><BR>
<a href="http://homeip.org/link/linktest/cart.cgi?cmd=remove;itemID=1003">-1003</a> <BR><BR>
<a href="http://homeip.org/link/linktest/cart.cgi?cmd=remove;itemID=1004">-1004</a> <BR><BR>
<a href="http://homeip.org/link/linktest/cart.cgi?cmd=remove;itemID=1005">-1005</a> <BR><BR>
<%-- cart end --%>
Quote Reply
Re: [courierb] weird problem on form get and post method as well as Links::init_user() In reply to
Do you have an error log? If so, try adding debugging at different points in the script, for example:

print STDERR qq|ok, we are here at line | . __LINE__ . qq|\n|;

Then, you can see where its getting too. Not sure, but sounds like it may just be a case of a never ending loop (i.e calling a function, and it keeps trying to call itself again and again, until eventually it timesout, or you get an "out of memory" error)

Totally wild stab in the dark - but worth a check :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] weird problem on form get and post method as well as Links::init_user() In reply to
Hi andy

thanks for the reply.

i think it is the problem of CGI incompatible with GT module.
as they rewirte cgi modue.


for your suggestion, i may have a try. but i never do that before.
i just try to follow your instrunction to do it step by step.
Quote Reply
Re: [courierb] weird problem on form get and post method as well as Links::init_user() In reply to
Dear Andy.


it is fall into endless loop then why i changed form method to "get", it works well. i get expecting result.
however. all parameter are show on the ie address line. so i need to use post method instead.
Quote Reply
Re: [courierb] weird problem on form get and post method as well as Links::init_user() In reply to
Why don't you use

my $cgi = new GT::CGI;

.. instead of

my $cgi = new CGI;

?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] weird problem on form get and post method as well as Links::init_user() In reply to
Andy

I did try to add
use GT::CGI;
my $cgi = new GT::CGI;



it was worse as i was returned
CGI ErrorThe specified CGI application misbehaved by not returning a complete set of HTTP headers.

the reason i use cgi as i don;t use gt:cgi:session as it is lack of document.

Last edited by:

courierb: Jul 13, 2009, 3:40 AM
Quote Reply
Re: [courierb] weird problem on form get and post method as well as Links::init_user() In reply to
  

when i uncomment #Links::init_user(); , the script runs well.

when it run though the sub routine. it hangs in step

#print Links::SiteHTML::display('8gtcart', $tags);

as i replace it with a simple print statement
print " Oops!!! Error<br><br>$cmd<br>$name $itemIDnum $price $quantity <br>\n";
it runs well as i expected.



sub display_cart {
my ($cgi, $session,$product,$tags) = @_;
# getting the cart's contents
#my $cart = $session->param("CART") || []; # this has been getting in the next few line foreach my $product ( @{$session->param('CART')} )
my $tags;
$tags->{total_price} = 0;
foreach my $product ( @{$session->param('CART')} ) {
$product->{prod_subtotal} = $product->{price} * $product->{quantity};
$tags->{total_price} += $product->{prod_subtotal};
$tags->{itemmaxtemp}=$itemmaxtemp;
$tags->{itemID}=$itemID;
push @{$tags->{cart_loop}}, $product;
}

print $IN->header();
print " Oops!!! Error<br><br>$cmd<br>$name $itemIDnum $price $quantity <br>\n";
#print Links::SiteHTML::display('8gtcart', $tags);
exit;
}



maybe you are right . it has be something wrong with loop. but i don't know how to fix it
Quote Reply
Re: [courierb] weird problem on form get and post method as well as Links::init_user() In reply to
Hi,

Mmmm. ok - afraid I'm out of suggestions, sorry :( Maybe someone at GT could give some feedback.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [courierb] weird problem on form get and post method as well as Links::init_user() In reply to
Hi,

I am not sure if this case

Code:
use lib 'D:\webtest\merchant\linkcart\admin';
...
Links::init('D:\webtest\links\admin'); ########
In all "built-in" cgi files, the two path are the same. In your file, they are not.

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] weird problem on form get and post method as well as Links::init_user() In reply to
thanks a lot tandat. it is nothing with the path. i have tested ....
Quote Reply
Re: [courierbb] weird problem on form get and post method as well as Links::init_user() In reply to
That sounds strange. Does other cgi files like add.cgi, modify.cgi, user.cgi, etc. have the same problem? These files also have that line. If not, you must recheck yours.

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [courierb] weird problem on form get and post method as well as Links::init_user() In reply to
 
after do a simple replacement testing
i found Links::init_user(); is work well with GT:cgi while it fails when i replace GT::CGI with CGI.

it seems i have to stick on with GT:CGI and GT::Session? as GT module may has unexpected problem with cgi or cgi::session.

could anybody show me a simple working sample of GT::Session( GT::Session::file or GT::Session:sql)? so i could follow it to make modification?
Again. finally . i have to abandon the cgi and cgi::sesion .

Many thanks in advance






#!/usr/bin/perl
#use cgi;
#use GT::CGI; ##( have to comment it or it show me blank screen . why? this scirpt runs on D:\links\ )

#use CGI qw/:standard/;

use CGI::Session;
use Data::Dumper;
use lib 'D:\links\admin';
use Links qw/:objects/; # or whatever $IN, $DB, $CFG, $USER etc...
use Links qw/$USER/;
Links::init('D:\links\admin'); #########################
Links::init_user(); # gets the user information

use Links::SiteHTML; # if your using templates

#my $cgi = new CGI;
my $cgi = new GT::CGI;
#### replace cgi by GT::cgi now it works well even i uncooment line of Links::init_user(); while it runs faillure if using cgi instead of GT::CGI

my $session = new CGI::Session(undef, $cgi, {Directory=>'c:/tmp/carttmp'});

my $itemIDnum = $cgi->param('itemIDnum') || 1;
my $itemID = $cgi->param('itemID') || 1;
my $name = $cgi->param('name') || 1;
my $price = $cgi->param('price') || 1;
my $quantity = $cgi->param('quantity') || 1;
my $cmd = $cgi->param('cmd') || 1;




Print "Pragma: no-cache\n";
print "Content-type:text/html\n\n";
print " testing testing<br>$cmd<br>$name $itemIDnum $price $quantity <br>\n";
Quote Reply
Re: [tandat] weird problem on form get and post method as well as Links::init_user() In reply to
Hi tandat,

i think the problem is i am using cgi and cgi session. while all others scripts you mentioned as part of linksql.. using GT module only.
i do not know exactly why . you could have a try. that is simple script. just place it in your cgi bin of linksql
Quote Reply
Re: [courierb] weird problem on form get and post method as well as Links::init_user() In reply to
thanks for all the help

it is ok now


i have change cgi to GT::cgi

there is no conflict now. everything seems running well now


anyway thanks for the attention and help/
Quote Reply
Re: [courierb] weird problem on form get and post method as well as Links::init_user() In reply to
Whats with using 2 accounts on the forum? =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] weird problem on form get and post method as well as Links::init_user() In reply to
  

haaaaaaaaaa. the first one lost the password. and it take long times never reiceved temp password via email when i use online tools to find back password.

SSSSSSSSSSSSo. i regist a new one. as i try to tell you that i have settle the problem already.


That is it.

Cheers