Solved

Query String Problem If Form Is called With An Image Button

Posted on 2006-11-26
7
184 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Simple Linear Regression
Progress

690 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