Got an issue with Validating my Inputs. As you can see from the image I have only filled out one field, but I can still hit Submit and it will run as if it was filled out.
Here is an example, so you can get started. So you do not really need New-UDInputField, each parameter from your param definition will be used as UDInputField (textbox).
New-UDInput -Title "Input Form" -Validate -SubmitText "Create User" -Id "selfservice_input_form_validate" -Endpoint {
param(
[Parameter(Mandatory, HelpMessage = "First name")]
[ValidateNotNullorEmpty()]
[string]$FirstName,
[Parameter(Mandatory, HelpMessage = "Last name")]
[ValidateNotNullorEmpty()]
[string]$LastName,
[Parameter(Mandatory, HelpMessage = "Username (sAMAccountName")]
[ValidateNotNullorEmpty()]
[string]$UserName,
[Parameter(Mandatory, HelpMessage = "Hostname (max. 15 characters)")]
[UniversalDashboard.ValidationErrorMessage("The hostname you entered is invalid because it contains illegal characters (only lowercase, letters, numbers and dashes - 1-15 characters)")]
[ValidateLength(1, 15)]
[ValidatePattern('[a-z0-9-]')]
[string]$Hostname,
[UniversalDashboard.ValidationErrorMessage("The ip address you entered is invalid.")]
[Parameter(Mandatory, HelpMessage = "IP address" )]
[ValidateScript( { $_ -is [ipaddress] })]
[ipaddress]$IPAddress,
[Parameter(Mandatory = $false, HelpMessage = "Homepage for this user")]
[string]$Homepage,
[Parameter(Mandatory, HelpMessage = "Email address")]
[UniversalDashboard.ValidationErrorMessage("The email address you entered is invalid.")]
[ValidatePattern('^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$')]
[System.Net.Mail.MailAddress]$Mail,
[Parameter(Mandatory, HelpMessage = "6 digit Employee ID")]
[ValidateLength(6, 6)]
[ValidatePattern("^[0-9]*$")]
[UniversalDashboard.ValidationErrorMessage("The employee id you entered is invalid.")]
$EmployeeID
)
}
Edit: Here is an example of the result
(reminder for me: I need to do a better css config for my input form… (this is only an internal example))
My issue is still that if I fill out everything except ‘First Name’(Didn’t clicked the textbox), I can still ‘Create User’ and ‘First Name’ is never validated and the script will continue to run.