Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Adding a pop up confirmation box

by poj (Priest)
on Jul 06, 2014 at 14:03 UTC ( #1092473=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Adding a pop up confirmation box
in thread Adding a pop up confirmation box

Another option is to add a step with another form and hidden fields. Refactored it would look something like this.

#!/usr/local/bin/perl use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; #remove for prod use DBI; # get form parameters my $q = new CGI; my $action = $q->param('go'); my $empid = $q->param('empid'); my $dbh = dbh(); # connect to db $dbh->do("SET search_path to northwind") or die; # If the confirm form was properly submitted, delete the record my $msg; # change validation to suit if ( ($action eq "Confirm Delete") && ($empid =~ /\d+/)) { my $sql = qq! DELETE FROM "Employees" WHERE "EmployeeID" = ? !; my $count = $dbh->do( $sql,undef,$empid ); $msg = "$count Record deleted - $sql, $empid"; } else { $msg = "Please complete form"; } # get employees my $sql = qq!SELECT "EmployeeID" AS empid, "FirstName"::text || ' ' ||"LastName"::text AS name FROM "Employees" !; my $ar = $dbh->selectall_arrayref($sql); # Make up a pulldown menu my $options = qq!<option value="">select name</option>!; for my $row (@$ar) { $options .= qq!<option value="$row->[0]">$row->[1]</option>\n!; } # build html page my $style = q! body { background-color: pink ; color: #3300cc; } .container { width: 500px; clear: both; } .container input { width: 100%; clear: both;} !; # Send out the header and form print $q->header; print $q->start_html(-title=>'Delete an employee record', -style=>{ -code=>$style } ); print qq!<h1 style="color:3300CC">Delete an employee</h1>!; # confirm delete form if ( $action eq "DELETE" ) { print qq!<h3>Are you sure you want to delete $empid ?</h3> <form action="" method="post"> <input type="hidden" name="empid" value="$empid"/> <input type="submit" name="go" value="Confirm Delete"/> <input type="submit" name="go" value="Cancel"/> </form>!; } else { print qq!<div class="container"> Select Employee name to delete : <form method="post" action=""> <select name="empid"> $options </select><br/> <input type="submit" name="go" value="DELETE"/> </form></div><hr/>!; # Standard links to the rest of the application print <<"FOOTER"; <b>$msg</b> <hr/> Jump to - <a href="emp2.pl">View Employees Listing</a><br/> Jump to - <a href="addemp.pl">Add an Employee</a><br/> Jump to - <a href="updatephoto.pl">Add or update Employee Photo</a><br +/> <hr/> Edited by Terry on July, 06 2014. FOOTER } print $q->end_html; # connect to database sub dbh { my $dsn = 'DBI:Pg:dbname=northwind;host=localhost'; my $user = '***'; my $pwd = '***'; my $dbh = DBI -> connect($dsn,$user,$pwd,{'RaiseError' => 1}); return $dbh; }
poj


Comment on Re^3: Adding a pop up confirmation box
Download Code
Re^4: Adding a pop up confirmation box
by terrykhatri (Acolyte) on Jul 07, 2014 at 06:11 UTC
    Hi Poj, This is absolutely marvelous, excellent code, works like a charm. Thank you very very much, I do appreciate your kind help all the time. Rgds Terry

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1092473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2015-07-03 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (56 votes), past polls