473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Form verification not verifying?

Hey, all.

I have a perl script which generates the html listed below. I cleaned it
up a bit since the perl CGI module creates some really ugly html code.
I've looked at this thing 8 ways to Sunday, but I can't see anything wrong.
When I hit the "Add" button, it immediately executes the action of the form
skipping the validate_form function completely.

I've tried the script section towards the top of the html as well as
just before the </body></html> without success.

I'm betting it's a simple mistake, but for the life of me, I can't find
it. Can someone tell me what I've screwed up?

Thanks for your time.

Doug O'Leary

HTML/javascript code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head><title>Add Nagios monitored host</title>
<link rev="made" href="mailto:dkoleary%40olearycomputers.com"></head>
<body>
<h1>Add Nagios Monitored Host</h1>
<p>Fields in <font color="red">red</font> are required</p>
<form method="post" action="/cgi-bin/run_this_command"
onsubmit="return validate_form(this)">
<table><tbody>
<tr>
<td><button type="submit" onclick="return validate_form(this)">
<big>Add</big></button></td>
<td><button
onclick="location.href='/nagios/cgi-bin/nadmin?func=display_hosts';
return false;">
<big>Reset</big></button></td>
</tr>
<tr>
<td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>
<tr>
<th align="left">Field</th>
<th align="left">Value</th>
<th align="left">Description</th>
</tr>
<tr bgcolor="silver">
<td><font color="red">host_name</font></td>
<td><input name="host_name" length="20" type="text"></td>
<td>Host name</td>
</tr>
<tr>
<td><font color="red">alias</font></td>
<td><input name="host_name" length="20" type="text"></td>
<td>Nagios alias</td>
</tr>
<tr bgcolor="silver">
<td><font color="red">address</font></td>
<td><input name="host_name" length="20" type="text"></td>
<td>IP address</td>
</tr>
<tr>
<td>parents</td>
<td><input name="parents" size="20" value="DEFAULT" type="text"></td>
<td>Hosts between Nagios server and host_name</td>
</tr>
<tr bgcolor="silver">
<td>check_command</td>
<td><select name="check_command">
<option selected="selected" value="" default="">DEFAULT</option>
<option value="check-host-alive">check-host-alive </option>
<option value="check_dns">check_dns </option>
<option value="check_ftp">check_ftp </option>
<option value="check_hpjd">check_hpjd </option>
<option value="check_http">check_http </option>
<option value="check_http_path">check_http_path </option>
<option value="check_http_port">check_http_port </option>
<option value="check_imap">check_imap </option>
<option value="check_local_disk">check_local_disk </option>
<option value="check_local_load">check_local_load </option>
<option value="check_local_procs">check_local_procs </option>
<option value="check_local_users">check_local_users </option>
<option value="check_nntp">check_nntp </option>
<option value="check_nt_clientversion">check_nt_clientvers ion </option>
<option value="check_nt_cpuload">check_nt_cpuload </option>
<option value="check_nt_disk">check_nt_disk </option>
<option value="check_nt_fileage">check_nt_fileage </option>
<option value="check_nt_memuse">check_nt_memuse </option>
<option value="check_nt_pagingfile">check_nt_pagingfile </option>
<option value="check_nt_process">check_nt_process </option>
<option value="check_nt_service">check_nt_service </option>
<option value="check_nt_service_nav">check_nt_service_nav </option>
<option value="check_nt_uptime">check_nt_uptime </option>
<option value="check_nwstat_load15">check_nwstat_load15 </option>
<option value="check_nwstat_vkf">check_nwstat_vkf </option>
<option value="check_nwstat_vpf">check_nwstat_vpf </option>
<option value="check_ping">check_ping </option>
<option value="check_pop">check_pop </option>
<option value="check_smtp">check_smtp </option>
<option value="check_ssh">check_ssh </option>
<option value="check_tcp">check_tcp </option>
<option value="check_telnet">check_telnet </option>
<option value="check_udp">check_udp </option>
<option value="host-notify-by-email">host-notify-by-email </option>
<option value="host-notify-by-epager">host-notify-by-epager </option>
<option value="notify-by-email">notify-by-email </option>
<option value="notify-by-epager">notify-by-epager </option>
<option value="process-host-perfdata">process-host-perfdata </option>
<option value="process-service-perfdata">
process-service-perfdata</option>
</select></td>
<td>Command used to verify host up/down.</td>
</tr>
<tr>
<td><font color="red">max_check_attempts</font></td>
<td><input name="max_check_attempts" value="10" type="text"></td>
<td>Max times to check host</td>
</tr>
<tr bgcolor="silver">
<td>checks_enabled</td>
<td><select name="checks_enabled">
<option selected="selected" value="DEFAULT">DEFAULT</option>
<option value="0">0</option>
<option value="1">1 </option>
</select></td>
<td>Whether or checks are enabled [0/1]</td>
</tr>
<tr>
<td>event_handler</td>
<td><select name="event_handler">
<option selected="selected" value="" default="">DEFAULT</option>
<option value="check-host-alive">check-host-alive </option>
<option value="check_dns">check_dns </option>
<option value="check_ftp">check_ftp</option>
<option value="check_hpjd">check_hpjd</option>
<option value="check_http">check_http</option></option>
<option value="check_http_port">check_http_port </option>
<option value="check_imap">check_imap </option>
<option value="check_local_disk">check_local_disk </option>
<option value="check_local_load">check_local_load </option>
<option value="check_local_procs">check_local_procs </option>
<option value="check_local_users">check_local_users </option>
<option value="check_nntp">check_nntp </option>
<option value="check_nt_clientversion">check_nt_clientvers ion </option>
<option value="check_nt_cpuload">check_nt_cpuload </option>
<option value="check_nt_disk">check_nt_disk </option>
<option value="check_nt_fileage">check_nt_fileage </option>
<option value="check_nt_memuse">check_nt_memuse </option>
<option value="check_nt_pagingfile">check_nt_pagingfile </option>
<option value="check_nt_process">check_nt_process </option>
<option value="check_nt_service">check_nt_service </option>
<option value="check_nt_service_nav">check_nt_service_nav </option>
<option value="check_nt_uptime">check_nt_uptime </option>
<option value="check_nwstat_load15">check_nwstat_load15 </option>
<option value="check_nwstat_vkf">check_nwstat_vkf </option>
<option value="check_nwstat_vpf">check_nwstat_vpf </option>
<option value="check_ping">check_ping </option>
<option value="check_pop">check_pop </option>
<option value="check_smtp">check_smtp </option>
<option value="check_ssh">check_ssh </option>
<option value="check_tcp">check_tcp </option>
<option value="check_telnet">check_telnet </option>
<option value="check_udp">check_udp </option>
<option value="host-notify-by-email">host-notify-by-email </option>
<option value="host-notify-by-epager">host-notify-by-epager </option>
<option value="notify-by-email">notify-by-email </option>
<option value="notify-by-epager">notify-by-epager </option>
<option value="process-host-perfdata">process-host-perfdata </option>
<option value="process-service-perfdata">process-service-perfdata</option>
</select></td>
<td>Command to run when state changes.</td>
</tr>
<tr bgcolor="silver">
<td>event_handler_enabled</td>
<td><select name="event_handler_enabled">
<option selected="selected" value="DEFAULT">DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not event handlers work. [0/1]</td>
</tr>
<tr>
<td>low_flap_threshold</td>
<td><input name="low_flap_threshold"
size="20" value="DEFAULT" type="text"></td>
<td>IDs the low state change threshold for flap detection</td>
</tr>
<tr bgcolor="silver">
<td>high_flap_threshold</td>
<td><input name="high_flap_threshold" size="20"
value="DEFAULT" type="text"></td>
<td>IDS the high state change threshold for flap detection. </td>
</tr>
<tr>
<td>flap_detection_enabled</td>
<td><select name="flap_detection_enabled">
<option selected="selected" value="DEFAULT">DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>IDs if flap detection is functional. [0/1]</td>
</tr>
<tr bgcolor="silver">
<td>process_perf_data</td>
<td><select name="process_perf_data">
<option selected="selected" value="DEFAULT">DEFAULT </option>
<option value="0">0 </option>
<option value="1">1 </option>
</select></td>
<td>Whether or not to process perf data. [0/1]</td>
</tr>
<tr>
<td>retain_status_information</td>
<td><select name="retain_status_information">
<option selected="selected" value="DEFAULT">DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not to retain state information [0/1]</td>
</tr>
<tr bgcolor="silver">
<td>retain_nonstatus_information</td>
<td><select name="retain_nonstatus_information">
<option selected="selected" value="DEFAULT">DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not to retain nonstatus information. [0/1]</td>
</tr>
<tr>
<td><font color="red">notification_interval</font></td>
<td><input name="notification_interval" value="120" type="text"></td>
<td>Wait specified # of time units before renotification. </td>
</tr>
<tr bgcolor="silver">
<td><font color="red">notification_period</font></td>
<td><select name="notification_period">
<option value="24x7">24x7 </option>
<option selected="selected" value="none">none </option>
<option value="nonworkhours">nonworkhours </option>
<option value="workhours">workhours</option>
</select></td>
<td>IDs timeperiod during which notifications can occur.</td>
</tr>
<tr>
<td><font color="red">notification_options</font></td>
<td><input name="notification_options" value="d,u,r" type="text"></td>
<td>IDs upon which state notificatons should be sent. [d,u,r]</td>
</tr>
<tr bgcolor="silver">
<td>notifications_enabled</td>
<td><select name="notifications_enabled">
<option selected="selected" value="DEFAULT">DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not notifications are enabled. [0/1] </td>
</tr>
<tr>
<td>stalking_options</td>
<td><input name="stalking_options" size="20"
value="DEFAULT" type="text"></td>
<td>IDS for which host states stalking is enabled [o,d,u]</td>
</tr>
<tr bgcolor="silver">
<td>register</td>
<td><select name="register">
<option selected="selected" value="DEFAULT">DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>IDs if host_name should be registered. Defaults to 1</td>
</tr>
</tbody>
</table></form>
<script>
function isNotEmpty(elem)
{ var str = elem.value;
if (str == null || str.length == 0)
{ alert("Please fill in hostname");
return false;
}
return true;
}
function validate_form(form)
{ if (isNotEmpty(form.host_name)
{ if (isNotEmpty(form.alias)
{ if (isNotEmpty(form.address)
{ return true;
}
}
}
return false;
}
function report_error(msg, url, line)
{ alert("Msg: " + msg);
alert("Line: " + line);
}
window.onerror = report_error;
</script>
</body></html>

Jul 23 '05 #1
10 2804
Doug O'Leary wrote:
Hey, all.

I have a perl script which generates the html listed below. I cleaned it up a bit since the perl CGI module creates some really ugly html code. I've looked at this thing 8 ways to Sunday, but I can't see anything wrong. When I hit the "Add" button, it immediately executes the action of the form skipping the validate_form function completely.

I've tried the script section towards the top of the html as well as
just before the </body></html> without success.

I'm betting it's a simple mistake, but for the life of me, I can't find it. Can someone tell me what I've screwed up?

Thanks for your time.

Doug O'Leary


(snip)

Couple of suggestions:

1) Change that <button> to an <input type="submit" value="Add">
2) Only call the validator from Form.onsubmit; once is plenty
3) Fix these: missing----> ) <----

function validate_form(form)
{ if (isNotEmpty(form.host_name) <----
{ if (isNotEmpty(form.alias) <----
{ if (isNotEmpty(form.address) <----
{ return true;

Always work with a console debugger enabled (MSIE: Tools>Internet
Options>Advanced>Display a notification... Moz/NS: Tools>[web
development]>JavaScript Console)

Jul 23 '05 #2
In article <sl*********************@linux.attbi.com>,
dk******@olearycomputers.com enlightened us with...
Hey, all.

I have a perl script which generates the html listed below. I cleaned it
up a bit since the perl CGI module creates some really ugly html code.
I've looked at this thing 8 ways to Sunday, but I can't see anything wrong.
When I hit the "Add" button, it immediately executes the action of the form
skipping the validate_form function completely.
How do you know it's skipping it?
Did you put an alert in there?
<script>
function isNotEmpty(elem)
{ var str = elem.value;
elem.value is undefined (not null) if elem is undefined (can't access a
property of a null object). Which you seem to have forgotten to check.

} function validate_form(form)
{
alert("in function");
Put that there so you can see if it's getting called. I bet it is.
if (isNotEmpty(form.host_name)
{ if (isNotEmpty(form.alias)


--
--
~kaeli~
When you choke a smurf, what color does it turn?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #3
RobB wrote:
Doug O'Leary wrote:
Hey, all.

I have a perl script which generates the html listed below. I cleaned it
up a bit since the perl CGI module creates some really ugly html

code.
I've looked at this thing 8 ways to Sunday, but I can't see anything wrong.
When I hit the "Add" button, it immediately executes the action of

the form
skipping the validate_form function completely.

I've tried the script section towards the top of the html as well

as just before the </body></html> without success.

I'm betting it's a simple mistake, but for the life of me, I can't

find
it. Can someone tell me what I've screwed up?

Thanks for your time.

Doug O'Leary


(snip)

Couple of suggestions:

1) Change that <button> to an <input type="submit" value="Add">
2) Only call the validator from Form.onsubmit; once is plenty
3) Fix these: missing----> ) <----

function validate_form(form)
{ if (isNotEmpty(form.host_name) <----
{ if (isNotEmpty(form.alias) <----
{ if (isNotEmpty(form.address) <----
{ return true;

Always work with a console debugger enabled (MSIE: Tools>Internet
Options>Advanced>Display a notification... Moz/NS: Tools>[web
development]>JavaScript Console)


More: just noticed you've got three text inputs named 'host_name'...if
you want to leave it that way, you'll need to reference them as
'host_name[0]', 'host_name[1]', 'host_name[2]'...why not call them what
they're labeled as (on the form)?

Jul 23 '05 #4
On 2005-03-17, RobB <fe******@hotmail.com> wrote:

Couple of suggestions:

1) Change that <button> to an <input type="submit" value="Add">
2) Only call the validator from Form.onsubmit; once is plenty
3) Fix these: missing----> ) <----

function validate_form(form)
{ if (isNotEmpty(form.host_name) <----
{ if (isNotEmpty(form.alias) <----
{ if (isNotEmpty(form.address) <----
{ return true;

Always work with a console debugger enabled (MSIE: Tools>Internet
Options>Advanced>Display a notification... Moz/NS: Tools>[web
development]>JavaScript Console)


Hey, thanks for the tips. The ending parens was the main issue.
There's still some work needed on the logic, but at least it's
alerting when it's supposesd to.

I initially had <inpt type="submit" value="add" thing; however,
I wasn't able to play with the font on the button text. After
looking through a bunch of manuals, I found that <button> is a
html ver 4.X which is supposed to do the same thing. Did I
misunderstand the text?

The second validate_form function was a troubleshooting addition
in a vain attempt to get this thing working. It'll be gone shortly.

Thanks again for your help.

Doug O'Leary

Jul 23 '05 #5
On 2005-03-17, RobB <fe******@hotmail.com> wrote:

More: just noticed you've got three text inputs named 'host_name'...if
you want to leave it that way, you'll need to reference them as
'host_name[0]', 'host_name[1]', 'host_name[2]'...why not call them what
they're labeled as (on the form)?


Nope; that's a bonehead error in the perl script that I'll have to
go back and correct. Thanks for pointing that out. I copied
quite a bit of the function that resulted in that html code from
another one. Probably means I screwed that one up too.

Thanks again for your help.

Doug

Jul 23 '05 #6
On 2005-03-17, RobB <fe******@hotmail.com> wrote:
More: just noticed you've got three text inputs named 'host_name'...if
you want to leave it that way, you'll need to reference them as
'host_name[0]', 'host_name[1]', 'host_name[2]'...why not call them what
they're labeled as (on the form)?


Nope; that was a boneheaded error in the perl script that I'll have to
go back and fix. Thanks for pointing that out. I copied the function
that resulted in that html code from another function in the script which
probably means I screwed that one up too.

Thanks again for your help.

Doug

Jul 23 '05 #7
Doug O'Leary wrote:
On 2005-03-17, RobB <fe******@hotmail.com> wrote:

More: just noticed you've got three text inputs named 'host_name'...if you want to leave it that way, you'll need to reference them as
'host_name[0]', 'host_name[1]', 'host_name[2]'...why not call them what they're labeled as (on the form)?


Nope; that's a bonehead error in the perl script that I'll have to
go back and correct. Thanks for pointing that out. I copied
quite a bit of the function that resulted in that html code from
another one. Probably means I screwed that one up too.

Thanks again for your help.

Doug


No problem. Here's something a bit more useful (imo):

function empty(field)
{
return /^\s*$/.test(field.value);
}

function validate_form(els)
{
var foc = null, msg = [];
if (empty(els.host_name))
{
msg.push('Host name');
foc = foc || els.host_name;
}
if (empty(els.alias))
{
msg.push('Nagios alias');
foc = foc || els.alias;
}
if (empty(els.address))
{
msg.push('IP address');
foc = foc || els.address;
}
if (msg != '')
{
var pre = 'The following fields were incomplete:\n\n';
var post = '\n\nPlease correct & resubmit.\n';
alert(pre + msg.join('\n') + post);
if (foc && foc.focus)
foc.focus();
return false;
}
return true;
}

<tr bgcolor="silver">
<td><font color="red">host_name</font></*td>
<td><input name="host_name" length="20" type="text"></td>
<td>Host name</td>
</tr>
<tr>
<td><font color="red">alias</font></td>
<td><input name="alias" length="20" type="text"></td>
<td>Nagios alias</td>
</tr>
<tr bgcolor="silver">
<td><font color="red">address</font></td*>
<td><input name="address" length="20" type="text"></td>
<td>IP address</td>
</tr>

Jul 23 '05 #8
Sorry, omitted this:

<form...onsubmit="return validate_form(this.elements)">

Works anyway (Form.element_name is the same as
Form.elements.element_name).

cya

Jul 23 '05 #9
Doug O'Leary wrote:

[snip]
I initially had <inpt type="submit" value="add" thing; however,
I wasn't able to play with the font on the button text.
You should be able to with CSS. However, styling form controls can be
tricky because some user agents will just pass handling to the OS so
they can't enforce the presentation.
After looking through a bunch of manuals, I found that <button> is a
html ver 4.X which is supposed to do the same thing.
The BUTTON element is much richer, and it would be nice to be able to
use it.
Did I misunderstand the text?


No, it's just that BUTTON isn't quite as reliable. NN4 (if you care
about such things) doesn't support it at all, and IE's behaviour (in
all versions) is /severely/ broken. Instead of submitting the value of
the element, it submits the content (equivalent to the proprietary
innerText property) instead. Still worse (and ignoring button is bad
enough), activating one submit BUTTON will submit the name/content
pairs of all of the other BUTTON elements (submit or otherwise) in the
form.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stephen Chell | last post by:
My java app gets an X509 certificate out of an XML signature, and I want to verify that the certificate is signed by any one of several trusted CAs. If we assume that all relevant CA...
14
by: Jack Kaufmann | last post by:
I am trying to verify a datagrid in which there must be an entry in both columns of any new row, and those values must be greater than the corresponding values in the previous row. It is pretty...
3
by: Yossi Kreinin | last post by:
Hi! Is there a summary of the rules C++ code should obey, but an implementation doesn't have to verify it does? For example, the one definition rule or the prohibition to dereference a null...
14
by: Oleg | last post by:
Hello there: I've been trying to create two different sets of required fields in one form and to use a radiobutton as sort of a switcher between these sets. In my HTML form there are two...
2
by: Ws | last post by:
Hi all I'm trying to write up a module that *safely* sets sys.stderr and sys.stdout, and am currently having troubles with the function verification. I need to assure that the function can...
6
by: Spycat | last post by:
Hi all and happy holidays! I should start off by stating I am NOT a PHP programmer. I say that so that in any response to me, you will speak very s-l-o-w-l-y or I won't know what you're talking...
3
clintw
by: clintw | last post by:
My problem. I have a html contact form that is being spammed. So I have set .html to be treated as .php, in order to include php image verification into the form. However, the Action on the form...
3
by: bonus | last post by:
Im new at Javascripting and jumped in the ocean and Im a little lost, I am trying to get a form to do 2 things: 1) write a cookie (actually several cookies) 2) submit the information to a php...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.