Solved

Query String Problem If Form Is called With An Image Button

Posted on 2006-11-26
7
179 Views
Last Modified: 2010-04-16
Hi All

I have finally tracked down my .x .y problem that I been having. The problem is created when I use an “image” to submit a form perl must supply X and Y coordinates of the mouse pointer.

The incoming string looks like this when a image is used to submit a form and is stored in @pairs:
SpecialButton::FrameColor.x=55 SpecialButton::FrameColor.y=15 Rest of string……
Or:
Rest of string…… FrameColor=Silver Metal x=45 y=10


Im using this to split up the incoming values:

if ($ENV{'REQUEST_METHOD'} eq 'POST') {
  read(STDIN, $Buffer, $ENV{'CONTENT_LENGTH'});
} else {
  $Buffer = $ENV{'QUERY_STRING'};
}

my $QueryString = "$Buffer";

@Pairs = split(/&/, $Buffer);

foreach $Pair (@Pairs) {
  ($Name, $Value) = split(/=/, $Pair);
 $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;

  $FORM{$Name} = $Value;
}

I know I should be using CGI but I’m not! and just need to fix this problem.

What I need is to only have is this:
SpecialButton::FrameColor Rest of string……

If called like:
SpecialButton::FrameColor.x=55 SpecialButton::FrameColor.y=15 Rest of string……

Or this
Rest of string…… FrameColor=Silver Metal

If called like this:
Rest of string…… FrameColor=Silver Metal x=45 y=10

I need to loose the .x=55 and the .y=15 remember the numbers will change or the x=45 y=10 If called the other way

Also I need to loose any “duplicates” of SpecialButton:: the SpecialButton can carry any value after the :: so SpecialButton:: can look like this:

SpecialButton::FrameColor
SpecialButton::Style
SpecialButton::AnythingCanGoHere

0
Comment
Question by:blnukem
  • 5
  • 2
7 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 18014913
Your description of the problem and what you need to accomplish is not very clear, but I'd say the source of the problem is here ->> “I know I should be using CGI but I’m not!”

Get rid if the messy and outdated form processing code and if you want the form submission in a hash, do this:

use CGI;
my $q = new CGI;
my %form = $q->Vars;

However, I suspect that you might want to look into going with this route.

use CGI ':standard';

my $framecolorX = param('SpecialButton::FrameColor.x');
my $framecolorY = param('SpecialButton::FrameColor.y');
etc
etc
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 18015249
>> Also I need to loose any “duplicates” of SpecialButton:: the SpecialButton can carry any value after the ::

If you put the form submission into a hash (either by the current messy approach or by the CGI module), you can remove the SpecialButton:: from the names of the keys by coping them into a new key/value and then delete the original.

foreach my $key (keys %form) {
   my ($newkey) = $key =~ /SpecialButton::(.*)/;
   $form{$newkey} = $form{$key} and delete $form{$key};
}
0
 
LVL 28

Accepted Solution

by:
FishMonger earned 500 total points
ID: 18015256
I guess I should put that into conditional.

if ($newkey ) { $form{$newkey} = $form{$key} and delete $form{$key}; }
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 28

Expert Comment

by:FishMonger
ID: 18031929
blnukem did you try either of my suggestions?

Did they help resolve your problem?

If not, can you provide more details on what you need so that I and/or anyone else can provide a proper solution.
0
 

Author Comment

by:blnukem
ID: 18045195

 FishMonger
 
   Sorry, I was away will test today, But I can tell you I will need a regex to remove the any incoming value that contains .x or .y because the use of CGI is out of the question "For Now, I don't have the time to fix all of the code" I just need to remove the bug for now.
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 18045817
I'm not sure if you're saying that you need to change the names of the %FORM keys or their values.  If you need to change the names of the keys, then the foreach loop I showed will do the trick, but may need a slight adjustment to get the names you want.  If that doesn't work, then you'll need to give more details on exactly what you need, because the description in your question is confusing.
0
 

Author Comment

by:blnukem
ID: 18084033
FishMonger

The second part works fine so I’m going to give you the points but I really need to fix the first part of my problem so I’m going to re-ask the question in the Perl category I seem to have posted this in the Programming category by mistake.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now