in reply to All attempts to match data from input fail. Please help.

And because reasons… and because <readmore/> is so hard to spell…

File 1066091.cgi

#!/usr/bin/env perl use strictures; use CGI qw(:standard); use Data::Validate::IP "is_ipv4", "is_ipv6"; use Data::Validate::Domain "is_domain"; use JSON; if ( my $thing = param("ip_or_domain") ) { print header("application/json"), to_json({ ipv4 => is_ipv4($thing) ? \1 : \0, ipv6 => is_ipv6($thing) ? \1 : \0, domain => is_domain($thing) ? \1 : \0 }); } else { print header("text/html"), start_html(-title => "OHAI", -script => { -type => "text/javascript", -src => "//ajax.googleapis.com/ajax/li +bs/jquery/1.10.2/jquery.min.js" }), h1("MUCH IP. SO OCTET. WOW."), start_form(), p({-style => "width:48%; display:inline-block; text-align:righ +t", -class => "label"}, "IP or Domain"), p({-style => "padding-left:1%;width:50%; display:inline-block" +}, textfield(-name => "ip_or_domain", -style => "width:17em", -placeholder => "Enter an IP or Domain to verify +")), p({-style => "text-align:center", -class => "results"}), end_form(), <<' __jQuery', # The leading four spaces have to match at e +nd. <script type="text/javascript">jQuery(function($){ var $in = $("input[name=ip_or_domain]"); var $form = $in.closest("form"); $form.submit(function(e){ e.preventDefault() }); $in.keyup(function(e){ $(".results").children().remove(); $.ajax({ dataType: "json" ,url: "/" ,data: { ip_or_domain:$in.val() } ,success: function(data){ for ( var key in data ) { if ( data.hasOwnProperty(key) && data[key] ) { var $i = $("<div style='color:#900'></div +>"); $i.hide(); $(".results").append($i); $i.text("Looks like " + key).fadeIn(); } } if ( ! $(".results").children().length ) $(".results").hide().append("<i>nothing</i>") +.fadeIn(); } }); }); })</script> __jQuery end_html() ; } exit 0;

Update: moved the end_html().

Run it and visit it, probably at http://localhost:8080…

plackup -l :8080 -L Shotgun -MPlack::App::WrapCGI \ -e 'Plack::App::WrapCGI->new( script => "1066091.cgi" )'

Don’t write code like this so close to Christmas. You will make the baby Jesus cry.

Replies are listed 'Best First'.
Re^2: All attempts to match data from input fail. Please help.
by taint (Chaplain) on Dec 07, 2013 at 03:56 UTC
    WOW. I'm overwhelmed, Your Mother.

    Nice complete, piece of work!

    It gives me goose bumps, all over.

    ^%#^%# Now I'll have to find something at least as nice, to give you, in return. For Christmas.

    Seriously. Thanks. :)

    --Chris

    Hey. I'm not completely useless. I can be used as a bad example.