Actually I have a CGI form which consists of
textfields and I need a combobox in which I can
enter my own data dynamically. May be it seems very
silly question but I am new to cgi-perl as well as
HTML so no idea what to do. Here is my form: - #!C:\perl\bin\perl.exe
-
-
use CGI;
-
use CGI qw/:standard/;
-
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
-
my $q = new CGI;
-
use DBI;
-
use CGI qw(:all);
-
use strict;
-
use warnings;
-
print "Content-Type: text/html\n\n";
-
print $q->header ( );
-
-
if ( $q->param("submit") )
-
{
-
process_form ( );
-
}
-
else
-
{
-
display_form ( );
-
}
-
-
-
sub process_form
-
{
-
if ( validate_form ( ) )
-
{
-
display_form ( );
-
}
-
}
-
-
-
sub validate_form
-
{
-
my $User_Name = $q->param("User_Name");
-
my $User_Password= $q->param("User_Password");
-
my $User_Permission = $q->param("User_Permission");
-
my $User_Department= join(", ",$q->param
-
("User_Department"));
-
my $error_message = "";
-
$error_message .= "Please enter your name<br/>" if
-
( !$User_Name );
-
$error_message .= "Please enter your Password<br/>"
-
if( ! $User_Password );
-
$error_message .= "Please Select a permission<br/>"
-
if( !$User_Permission );
-
$error_message .= "Please select atleast 1
-
department<br/>" if(!$User_Department);
-
-
if ( $error_message )
-
{
-
display_form (
-
$error_message,$User_Name,$User_Password,$User_Per mission
-
,$User_Department);
-
return 0;
-
}
-
else
-
{
-
my $dbh = DBI->connect
-
("dbi:SQLite:DEVICE.db","", "",{RaiseError => 1,
-
AutoCommit =>
-
1 } );
-
my $sql = "SELECT COUNT(UserName) FROM UsersList
-
WHERE UserName='$User_Name'";
-
my $sth = $dbh->prepare($sql) or die("\n\nPREPARE
-
ERROR:\n\n$DBI::errstr");
-
$sth->execute or die("\n\nQUERY
-
ERROR:\n\n$DBI::errstr");
-
my ($n) = $dbh->selectrow_array($sth);
-
$sth->finish();
-
if ($n > 0) {
-
print "Record Already Exists";
-
}
-
else {
-
my $sql = "INSERT INTO UsersList
-
(UserName,Password,Permission,Department) VALUES
-
('$User_Name ','
-
$User_Password','$User_Permission','$User_Departme nt')";
-
my $sth = $dbh->prepare($sql);
-
$sth->execute;
-
print "Record Added Successfully";
-
$sth->finish();
-
$dbh->commit or die $dbh->errstr;
-
}
-
$dbh->disconnect;
-
}
-
}
-
-
sub display_form
-
{
-
my $error_message = shift;
-
my $User_Name = shift;
-
my $User_Password = shift;
-
my $User_Permission= shift;
-
my $User_Department= shift;
-
-
my $User_Permission_Add_sel = $User_Permission
-
eq "Add" ? " checked" : "";
-
my $User_Permission_Edit_sel =$User_Permission
-
eq "Edit" ? " checked" : "";
-
my $User_Permission_Delete_sel =$User_Permission
-
eq "Delete" ? " checked" : "";
-
my $User_Permission_View_sel =$User_Permission
-
eq "View" ? " checked" : "";
-
-
my $User_Department_html = "";
-
my $dbh = DBI->connect
-
("dbi:SQLite:DEVICE.db","", "",{RaiseError => 1,
-
AutoCommit =>
-
1 } );
-
my $sql = "select DepartmentName from Departments
-
order by DepartmentName";
-
my $sth = $dbh->prepare($sql);
-
$sth->execute() ;
-
-
while (my $User_Department_option= $sth-
-
>fetchrow_array)
-
{
-
$User_Department_html.= "<option
-
value=\"$User_Department_option\"";
-
$User_Department_html.= " selected" if (
-
$User_Department_option eq
-
$User_Department );
-
-
$User_Department_html.= ">$User_Department_option</option
-
>";
-
}
-
$sth->finish();
-
$dbh->commit or die $dbh->errstr;
-
print <<END_HTML;
-
<html>
-
<head><title>Form Validation</title></head>
-
<body>
-
-
<form action="AddUser.cgi" method="post">
-
<input type="hidden" name="submit" value="Submit">
-
-
<p>$error_message</p>
-
-
-
<TABLE BORDER="1" align="center">
-
<TR>
-
<TD>Name</TD>
-
<TD> <input type="text" name="User_Name"
-
value="$User_Name"></TD>
-
</TR>
-
-
<TR>
-
<TD>Password</TD>
-
<TD colspan="2"><input type="password"
-
name="User_Password" value="$User_Password"
-
size="20" maxlength="15" /></TD>
-
-
</TR>
-
<TR>
-
<TD>Role</TD>
-
<TD>"HERE I NEED A COMBOBOX"</TD>
-
</TR>
-
-
<TR>
-
<TD>Permission</TD>
-
<TD><input type="radio" name="User_Permission"
-
value="Add"$User_Permission_Add_sel>Add<input
-
type="radio" name="User_Permission"
-
value="Edit"$User_Permission_Edit_sel>Edit<input
-
type="radio"
-
name="User_Permission"
-
value="Delete"$User_Permission_Delete_sel>Delete<i nput
-
type="radio" name="User_Permission"
-
value="View"$User_Permission_View_sel>View</TD>
-
</TR>
-
-
<TR>
-
<TD>Department</TD>
-
<TD colspan="2"> <select name="User_Department"
-
MULTIPLE
-
SIZE=4>$User_Department_html</select></TD>
-
-
</TR>
-
</TR>
-
<TR>
-
<TD align="center" colspan="2">
-
<input type="submit" name="submit" value="ADD">
-
</TD>
-
</TR>
-
</TABLE
-
</form>
-
-
</body></html>
-
END_HTML
-
-
}
1 2626 numberwhun 3,509
Recognized Expert Moderator Specialist
First, you really need to learn to enclose your code in code tags. After even as little as 6 posts you should have been instructed to do this before. Please be sure and do it in the future.
As for the combo box, you should really learn some HTML and learn how to add it. You say you don't know any, then can we assume that you got this code from elsewhere?
Regards,
Jeff
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Matt |
last post by:
I have a html form, and I want to transform html form data to xml
string. Given XSD (xml schema), how to transform the form data to xml
string?
|
by: Adam Retter |
last post by:
Hi Guys,
I have a need to create a html form based on my schema. I initially
decided to do this using xql, have got some way but am finding this
difficult (it may be as I am very new to xql)....
|
by: ojvm |
last post by:
ok. thanks again for the time spend reading this.
this code adds 2 controls in html form but it places in top of the
form.
i want this
control1 control2
control1 control2
control1 ...
|
by: Shahid |
last post by:
Hi,
I have an xml document, example below. I would like to create an HTML
form dynamically so all I would do is change the XML form in case a
different version comes.
I am relatively new...
|
by: Mark |
last post by:
Hi all, I have a WYSIWYG editor which allows people to insert a form into a
page.
This information is stored in a database and at run-time is displayed inside
a content placeholder (I'm using...
| |
by: patricksabourin |
last post by:
On my site,
I have 2 methods of displaying my data:
1) HTML form with select-option element. (Jump to different page when
clicking "Go" button"
2) HTML table with a hyperlink.
What I would...
|
by: John Wolff |
last post by:
I’m trying to upload a file to a Web Service. I have to submit the file
using a standard HTML form with the <input type=“file” /tag. Ultimately,
we are submitting the file from a Flash 8...
|
by: bp_jobemail |
last post by:
I'm trying to use PHP to wrap the output of an HTML form before it goes
into a precompiled C cgi script.
Essentially, the company that I work for uses a purchased precompiled c
program for their...
|
by: Lelu |
last post by:
Hi, My HTML form is generating some blank email
responses; does anyone see anything wrong with the scripts?:
function isFormVarExcluded(thisForm, strToCheck)
{
var strExcludeVars =...
|
by: AdminCyn |
last post by:
I am working on a project to update our website functionality; mainly I am suppose to create an HTML form for prospective tenants to fill out and submit via email; I have the html form done and...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |