Solved

Query String Problem If Form Is called With An Image Button

Posted on 2006-11-26
7
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBSCRIPT string remove all characters to the right after extension 4 71
Query Syntax 17 50
asp Google Map 2 60
Mutiple Folder view (5 Folder view) 3 50
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

749 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