Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; use CGI; use Data::Dumper; my $q = CGI->new(); print $q->header(); my $transac = $q->param( 'transac' ) || ''; # Get values my $user_name = $q->param( 'user_name' ) || ''; my $user_id = $q->param( 'userid' ) || ''; my $city_from = $q->param( 'city_from' ) || ''; my $state_from = $q->param( 'state_from' ) || ''; my $checkin_comments = $q->param( 'checkin_comments' ) || ''; print "<br>Display Results once the submit gets done: *$user_name*$use +r_id*$city_from*$state_from*$checkin_comments*<br>"; if($transac eq "checkin") { my $res = results(); print "<br> *$res* $user_name*$user_id*$city_from*$state_from*$check +in_comments*<br>"; }else { start_html(); } sub results { if ($user_name) { return 'success'; } else { return 'error'; } } # End sub results sub start_html { my $html_code = qq ( <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE> <html> <head> <meta http-equiv="Content-type" content="application/xhtml+xml; charse +t=utf-8" /> <meta http-equiv="Content-language" content="en-gb" /> <title>jquery from hell</title> <script type="text/javascript" src="/jquery/1.10.2/jquery.min.js"></sc +ript> <script type="text/javascript"> \$(function () { \$('.reply-comment').on('click', function (e) { e.preventDefault(); var form = \$('.reply-form'); var CommentID = \$(this).attr('id'); //alert(CommentID); if (form.is(':visible')) { // hide it form.hide(function () { \$('#' + CommentID).html('<a href="" class="reply-comment" i +d="reply-comment-' + CommentID + '"> [ Check-In ] </a>'); }); }else{ // show it form.show(function () { \$('#' + CommentID).html('<a href="" class="reply-comm +ent" id="reply-comment-' + CommentID + '">[ Cancel ]</a>'); }); } }); }); </script> <style> .reply-form { display:none; } </style> <script type="text/javascript" > function onSuccess(data, status) { data = \$.trim(data); alert(data); var form = \$('.reply-form'); var CommentID = 1; \$("form#reply-form").trigger('reset'); if (data) { // hide it form.hide(function () { \$('#' + CommentID).html('<a href="" class="reply-comment" i +d="reply-comment-' + CommentID + '"> [ xCheck-In ] </a>'); }); }else{ // show it form.show(function () { \$('#' + CommentID).html('<a href="" class="reply-comm +ent" id="reply-comment-' + CommentID + '">[ xCancel ]</a>'); }); } } function onError(data, status, e) { alert( "Sorry, there was a problem!" ); alert(data); console.log(e); } \$(document).ready(function(){ \$("form#reply-form").submit(function() { // reply-form is submitte +d var formData = \$("#reply-form").serialize(); // alert(formData); \$.ajax({ type: "post", url: "pjtest.pl", cache: false, data: formData, success: onSuccess, error: onError }); // return false to prevent normal browser submit and page navigati +on return false; }); }); </script> </head> <body bgcolor="#ffffff"> <table width="500" border="1" bgcolor="#ffffff" cellpadding="5" cellsp +acing="0"> <tr> <form name="postItem" action="test.pl" method=" +post" STYLE="margin: 0px; padding: 0px;"> <td align="center" width="33%" valign="bottom"> <input type="submit" id="submitLink" value="[ P +ost ]"> </td></form> <td align="center" width="34%" valign="middle"> <a href="" class="reply-comment" id="1"> [ Chec +k-In ] </a> </td> <form name="postItem" action="test.pl" method=" +post" STYLE="margin: 0px; padding: 0px;"> <td align="right" width="33%" valign="bottom"> <input type="submit" id="submitLink" value="[ +Log out ]"> </td> </form> </tr> </table> <!-- Check in stuff --> <div class="reply-form well"> <table width="100%" border="0" bgcolor="#1A1A1A" cel +lpadding="5" cellspacing="0"> <tr><form name="reply-form" id="reply-form" method= +"post" style="margin: 0px; padding: 0px;"> <input id="transac" type="hidden" name="tra +nsac" value="checkin"> <input id="user_name" type="hidden" name="u +ser_name" value="theusername"> <input id="userid" type="hidden" name="user +id" value="923"> <input id="city" name="city_from" type="hi +dden" value="Boston" /> <input id="state" name="state_from" type="h +idden" value="MA" /> <td align="center"> <textarea id="checkin_comments" name="check +in_comments" rows="4" cols="40" class="span10"></textarea> </td> <tr> <td align="center"> <!--input type="submit" id="submitLink" val +ue="[ Submit ]" /--> <input type="image" src="/images/check.png" + alt="Submit button" width="50" height="33" class="submit" id="send_c +omments"> </form> </td> </tr> </table> </body></html>); print $html_code; #return $html_code; } # End start_html sub
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Post back values using Perl and jQuery.
by Corion (Patriarch) on Jan 02, 2014 at 21:55 UTC | |
|
Re: Post back values using Perl and jQuery.
by Anonymous Monk on Jan 02, 2014 at 21:45 UTC | |
by Anonymous Monk on Jan 02, 2014 at 23:36 UTC | |
|
Re: Post back values using Perl and jQuery.
by locked_user sundialsvc4 (Abbot) on Jan 03, 2014 at 15:59 UTC |