• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Query String Problem If Form Is called With An Image Button

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
blnukem
Asked:
blnukem
  • 5
  • 2
1 Solution
 
FishMongerCommented:
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
 
FishMongerCommented:
>> 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
 
FishMongerCommented:
I guess I should put that into conditional.

if ($newkey ) { $form{$newkey} = $form{$key} and delete $form{$key}; }
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
FishMongerCommented:
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
 
blnukemAuthor Commented:

 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
 
FishMongerCommented:
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
 
blnukemAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now