Skip to content

Commit

Permalink
Add input validation for name
Browse files Browse the repository at this point in the history
  • Loading branch information
mickenordin committed Jun 27, 2019
1 parent f97bf8f commit 9b35d14
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/Thruk/Controller/api_conf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -491,19 +491,29 @@ sub display_editor {
return false;
}
}
function validateName () {
var str = document.getElementById("itemname").value;
if( /^[\w-.]+$/.test(str)) {
return true;
} else {
popitup("Invalid name! Please use only a-Z, 0-9 and _-. in the name field.");
return false;
}
}
</script>';
$textbox .= $q->p($head);
unless ( $page_type eq "services" and $mode eq "create" ) {
$textbox .= $q->start_form(
-method => $METHOD,
-action => "api_conf.cgi",
-id => "JSONForm",
-onSubmit => "return validateJSON()"
-onSubmit => "return validateJSON() && validateName()"
);
}
if ( $mode eq "create" ) {
$textbox .= $q->p("Enter $name name:");
$textbox .= $q->textfield( $name, '', 50, 80 );
$textbox .= $q->textfield( -name => $name, -id => 'itemname', -size => 50, -maxlength => 80 );
#$textbox .= $q->textfield( $name, '', 50, 80 );
$textbox .= $q->p("Editor:");
}
if ($hidden) {
Expand Down

0 comments on commit 9b35d14

Please sign in to comment.