in reply to Re: How to deal with multiple functions served from only one input field?
in thread How to deal with multiple functions served from only one input field?

++ to you ig.

Firstly. Please let me apologize for creating such a jumbled mess of a question. :(

Secondly. Thank you very much for your offered solutions.

While it was my intention to use just one form field to process either type of request. My posted attempts came from 2 different scripts. Because I haven't been able to figure out how to splice them together. Hence my question, and the confusing examples -- sorry.

OK I ran your first example up the flag pole. Here's the whole thing (note I haven't yet attempted to finalize the IP portion):

#!/usr/bin/perl -w use strict; use warnings; use CGI; use Net::Whois::Raw; use Net::Whois::ARIN; $Net::Whois::Raw::OMIT_MSG = 1; $Net::Whois::Raw::CACHE_TIME = 1; $Net::Whois::Raw::TIMEOUT = 8; my $q = new CGI; my $domname = $q->param("domname"); my $ip = $q->param("ip"); print "content-type:text/html; charset=utf-8\n\n"; print qq(<!DOCTYPE html> <head><title>igwhois</title></head><body>); print qq(<form method="post" action="/igwhois.cgi"> <fieldset> <label for="domname">Domain: </label><input type="text" name="domn +ame" /><br /> <label for="ip">IP: </label><input type="text" name="ip" /> </fieldset> </form>); if (!$domname) { print ""; } else { my $text = get_whois($domname, undef, "QRY_LAST"); print qq(<pre>); print $text; print qq(</pre>); } my $w = Net::Whois::ARIN->new( host => 'whois.arin.net', port => 43, timeout => 30, ); if (!$ip) { print ""; } else { my @records = $w->network($ip); foreach my $net (@records) { # print ...; } } print qq(</body></html>);
Sadly. Entering a domain name in the top field, and hitting enter, does nothing. It doesn't even post a query.
However. If I comment out the ip text field, and try it again. It works.
???

In a sick sort of way; this is refreshing. As I attempted a similar solution to the one you provided, and it reacted exactly the same.
So I don't feel quite so stupid now -- which is not to imply you are.

I'll take a shot at your second example, and see if I can get that one to work

Thank you again, ig, For all your time, and effort! I really appreciate it.

--Chris

#!/usr/bin/perl -Tw
use Perl::Always or die;
my $perl_version = (5.12.5);
print $perl_version;
  • Comment on Re^2: How to deal with multiple functions served from only one input field?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to deal with multiple functions served from only one input field?
by ig (Vicar) on Nov 15, 2013 at 10:13 UTC
    Sadly. Entering a domain name in the top field, and hitting enter, does nothing. It doesn't even post a query. However. If I comment out the ip text field, and try it again. It works. ???

    If you add a submit button, then Enter will submit the form even if there are multiple text inputs, at least in Firefox 25.0 (the only browser I tested). Without a submit button, Enter submits the form only if there is a single text input but doesn't submit the form if there are multiple text inputs.

    The following works for me:

    #!/strawberry/perl/bin/perl.exe use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); use Net::Whois::Raw; use Net::Whois::ARIN; $Net::Whois::Raw::OMIT_MSG = 1; $Net::Whois::Raw::CACHE_TIME = 1; $Net::Whois::Raw::TIMEOUT = 8; my $q = new CGI; my $domname = $q->param("domname"); my $ip = $q->param("ip"); print "content-type:text/html; charset=utf-8\n\n"; print qq(<!DOCTYPE html> <head><title>igwhois</title></head><body>); print qq( <form method="post"> <fieldset> <label for="domname">Domain: </label><input type="text" name="domn +ame" /><br /> <label for="ip">IP: </label><input type="text" name="ip" /> </fieldset> <input type="submit" value="Submit"> </form> ); if (!$domname) { print ""; } else { my $text = get_whois($domname, undef, "QRY_LAST"); print qq(<pre>); print $text; print qq(</pre>); } my $w = Net::Whois::ARIN->new( host => 'whois.arin.net', port => 43, timeout => 30, ); if (!$ip) { print ""; } else { my $text = $w->query("n + $ip"); print qq(<pre>); print $text; print qq(</pre>); } print qq(</body></html>);
      "If you add a submit button, then Enter will submit the form even if there are multiple text inputs, at least in Firefox 25.0 (the only browser I tested)."

      Of course! Because the form becomes an <ISINDEX> without it. I can be such an IDIOT, sometimes. Now I feel stupid again. Thanks alot ig. :)

      Seriously; thanks. I appreciate your pointing out what should have been obvious. This is the problem I stated earlier; I sometimes have an acute knack of making something extremely simple, a needlesslycomplex problem in my head. :P

      +'s to you again. Thank you very much, for your help, ig.

      --Chris

      #!/usr/bin/perl -Tw
      use Perl::Always or die;
      my $perl_version = (5.12.5);
      print $perl_version;