Solved

Query String Problem If Form Is called With An Image Button

Posted on 2006-11-26
7
181 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
silent install of security banner via msiexec command 4 87
index Out OF Range Exception error 4 61
iframe detection of parent window scale 20 71
SQL Insert parts by customer 12 31
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

786 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