Hi there Monks!
I am trying to use one script, that once this form gets submitted, it will update the database and post back the results to it-self. I am stuck trying to understand why once the form gets submitted and all the values get passed ( I can see all the values using firebug ) the results doesn’t show on the page like in this line: print "<br>Display Results once the submit gets done: *$user_name*$user_id*$city_from*$state_from*$checkin_comments*<br>"; What am I missing.
I have this test code that shows what I am trying to do:
#!/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 ]">&nbsp;&nbsp; </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

In reply to Post back values using Perl and jQuery. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.