> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/it/comandi-powershell/new-udform.md).

# New-UDForm

### Sinossi

I moduli possono contenere qualsiasi insieme di controlli di input. Ciascuno dei controlli riporterà il proprio valore al modulo quando si fa clic sul pulsante di invio.

### Sintassi

```powershell
New-UDForm [-Id <String>] [-OnValidate <Endpoint>] [-SubmitText <String>] [-CancelText <String>] [-ButtonVariant <String>] [-ClassName <String>] [-DisableSubmitOnEnter] [-Script <String>] [-OutputType <String>] [-ShowBackButton] [<CommonParameters>]

    New-UDForm [-Id <String>] -Children <ScriptBlock> -OnSubmit <Endpoint> [-OnValidate <Endpoint>] [-OnProcessing <ScriptBlock>] [-OnCancel <Endpoint>] [-SubmitText <String>] [-CancelText <String>] [-ButtonVariant <String>] [-ClassName <String>] [-DisableSubmitOnEnter] [<CommonParameters>]

    New-UDForm [-Id <String>] -OnSubmit <Endpoint> [-ButtonVariant <String>] [-ClassName <String>] -Schema <Hashtable> [-UiSchema <Hashtable>] [-FormData <Hashtable>] [-DisableSubmitOnEnter] [<CommonParameters>]
```

### Descrizione

Crea un nuovo modulo. I moduli possono contenere qualsiasi insieme di controlli di input. Ciascuno dei controlli riporterà il proprio valore al modulo quando si fa clic sul pulsante di invio.

### Parametri

#### -Id

L'ID del componente. Per impostazione predefinita è un GUID casuale.

```
Required?                    false
Position?                    named
Default value                [Guid]::NewGuid().ToString()
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Children

Controlli che compongono questo modulo. Può trattarsi di qualsiasi combinazione di controlli. I controlli di input riporteranno il proprio stato al modulo.

```
Required?                    true
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnSubmit

Un blocco di script che viene eseguito quando il modulo viene inviato. È possibile restituire controlli da questo blocco di script e il modulo verrà sostituito dal blocco di script. La variabile $EventData conterrà una hashtable di tutti i campi di input e dei relativi valori.

```
Required?                    true
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnValidate

Un blocco di script che convalida il modulo. Restituisce il risultato di una chiamata a New-UDFormValidationResult.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnProcessing

Un blocco di script che viene chiamato quando il modulo inizia l'elaborazione. Il valore restituito da questo blocco di script deve essere un componente che visualizza una finestra di dialogo di caricamento. Il blocco di script riceverà i dati correnti del modulo.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnCancel

Un blocco di script che viene chiamato quando un modulo viene annullato. Utile per chiudere i moduli nelle finestre modali.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -SubmitText

Testo da mostrare all'interno del pulsante di invio. Il valore predefinito è 'Submit'.

```
Required?                    false
Position?                    named
Default value                Submit
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -CancelText

Testo da mostrare all'interno del pulsante di annullamento. Il valore predefinito è 'Cancel'.

```
Required?                    false
Position?                    named
Default value                Cancel
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ButtonVariant

Tipo di pulsante da visualizzare. Il valore predefinito è text. I valori validi sono contained, outlined, text.

```
Required?                    false
Position?                    named
Default value                text
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ClassName

Una classe CSS da applicare al modulo.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Schema

Definisce un modulo basato su una hashtable di schema. Questa versione dei moduli è basata su react-jsonschema-form.

```
Required?                    true
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -UiSchema

Utilizzato per modificare l'ordinamento dei campi (vedere la documentazione)

```
Required?                    false
Position?                    named
Default value                @{}
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -FormData

```
Required?                    false
Position?                    named
Default value                @{}
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false

    -DisableSubmitOnEnter [<SwitchParameter>]
        Disables the functionality where pressing enter in a textbox submits the form it is a part of.

Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Script

Utilizzato per generare automaticamente moduli basati sugli script presenti nel proprio ambiente PowerShell Universal. I moduli di script generano componenti di input in base al blocco param. I moduli di script supportano automaticamente l'avanzamento e il feedback.

```
Required?                    false
Position?                    named
Default value                None
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OutputType

Il tipo di output da restituire dallo script. I valori validi sono: "Text", "Table"

```
Required?                    false
Position?                    named
Default value                Text
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false

    -ShowBackButton [<SwitchParameter>]
        Shows a back button after the form is submitted. This is only used for script forms.

Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
```

### Output

\-------------------------- ESEMPIO 1 --------------------------

```
PS >New-UDForm -Id 'form1' -Content {
PS >     New-UDTextbox -Id 'form1Textbox' -Label 'Name'
PS > } -OnSubmit {
PS >     Show-UDToast -Message ($EventData.form1Textbox)
PS > }

Basic|Creates a basic form.




-------------------------- EXAMPLE 2 --------------------------

PS >New-UDForm -Id 'form2' -Content {
PS >     New-UDTextbox -Id 'form2Textbox' -Label 'Name'
PS > } -OnSubmit {
PS >     Show-UDToast -Message ($EventData.form2Textbox)
PS > } -OnValidate {
PS >     if ($EventData.form2Textbox -eq 'Bob') {
PS >         New-UDValidationResult -ValidationError 'Bob is not allowed'
PS >     }
PS >     else {
PS >         New-UDValidationResult -Valid
PS >     }
PS > }

Validation|Creates a form with validation.




-------------------------- EXAMPLE 3 --------------------------

PS >New-UDForm -Id 'form3' -Content {
PS >     New-UDTextbox -Id 'form3Textbox' -Label 'Name'
PS > } -OnSubmit {
PS >     Start-Sleep -Seconds 5
PS >     Show-UDToast -Message ($EventData.form3Textbox)
PS > } -OnProcessing {
PS >     New-UDCard -Title 'Processing' -Content {
PS >         New-UDProgress
PS >     }
PS > }

Processing|Creates a form with a processing dialog.




-------------------------- EXAMPLE 4 --------------------------

PS >New-UDForm -Id 'form4' -Content {
PS >     New-UDTextbox -Id 'form4Textbox' -Label 'Name'
PS > } -OnSubmit {
PS >     Show-UDToast -Message ($EventData.form4Textbox)
PS > } -OnCancel {
PS >     Show-UDToast -Message 'Form was cancelled'
PS > }

Cancel|Creates a form with a cancel button.




-------------------------- EXAMPLE 5 --------------------------

PS >New-UDForm -Id 'form5' -Content {
PS >     New-UDTextbox -Id 'form5Textbox' -Label 'Name'
PS > } -OnSubmit {
PS >     Show-UDToast -Message ($EventData.form5Textbox)
PS > } -SubmitText 'Save' -CancelText 'Close' -OnCancel {
PS >     Show-UDToast -Message 'Form was cancelled'
PS > }

Submit and Cancel Text|Creates a form with custom submit and cancel text.




-------------------------- EXAMPLE 6 --------------------------

PS >New-UDForm -Id 'form6' -Content {
PS >     New-UDTextbox -Id 'form6Textbox' -Label 'Name'
PS > } -OnSubmit {
PS >     Show-UDToast -Message ($EventData.form6Textbox)
PS > } -ButtonVariant 'contained'

Button Variant|Creates a form with a contained button variant.




-------------------------- EXAMPLE 7 --------------------------

PS >New-UDForm -Id 'form7' -Content {
PS >     New-UDTextbox -Id 'form7Textbox' -Label 'Name'
PS > } -OnSubmit {
PS >     Show-UDToast -Message ($EventData.form7Textbox)
PS > } -ClassName 'my-form'

Class Name|Creates a form with a custom CSS class name.




-------------------------- EXAMPLE 8 --------------------------

PS >New-UDForm -Id 'form8' -Schema @{
PS >     title = "Test Form"
PS >     type = "object"
PS >     properties = @{
PS >        name = @{
PS >            type = "string"
PS >        }
PS >        age = @{
PS >            type = "number"
PS >        }
PS >     }
PS > } -OnSubmit {
PS >     Show-UDToast -Message ($EventData.name)
PS >     Show-UDToast -Message ($EventData.age)
PS > }

Schema|Creates a form with a schema. You can find out more about JSON Schema here: https://rjsf-team.github.io/react-jsonschema-form/docs/




-------------------------- EXAMPLE 9 --------------------------

PS >New-UDForm -Id 'form9' -Schema @{
PS >     title = "Test Form"
PS >     type = "object"
PS >     properties = @{
PS >        name = @{
PS >            type = "string"
PS >        }
PS >        age = @{
PS >            type = "number"
PS >        }
PS >     }
PS > } -uiSchema @{
PS >	"ui:order" = @('age','name')
PS > } -FormData @{ Name = "adam"; Age = 38 } -OnSubmit {
PS >     Show-UDToast -Message ($EventData.name)
PS > }

UI Schema|Creates a form with a schema and a UI schema. You can find out more about JSON Schema here: https://rjsf-team.github.io/react-jsonschema-form/docs/




-------------------------- EXAMPLE 10 --------------------------

PS >New-UDForm -Id 'form10' -Script "Script1.ps1" -OutputType "Table"

Script|Creates a form from a script. Parameters of the script will define the form. Output from the script will be displayed in a table.




-------------------------- EXAMPLE 11 --------------------------

PS >New-UDForm -Id 'form11' -Content {
PS >    New-UDTextbox -Id 'form11Textbox' -Label 'Name'
PS > } -OnSubmit {
PS >     Show-UDToast -Message ($EventData.form11Textbox)
PS > }
PS > New-UDButton -Text "A submit button outside the form" -OnClick {
PS >     Invoke-UDForm -Id "form11"
PS > }

Invoke-UDForm|Creates a form with a submit button outside the form.




-------------------------- EXAMPLE 12 --------------------------

PS >New-UDForm -Id 'form12' -Content {
PS >    New-UDTextbox -Id 'form12Textbox' -Label 'Name'
PS > } -OnSubmit {
PS >     Show-UDToast -Message ($EventData.form12Textbox)
PS > } -OnValidate {
PS >     if ($EventData.form12Textbox -eq 'Hello') {
PS >         New-UDValidationResult -Valid
PS >     }
PS >     else {
PS >         New-UDValidationResult -ValidationError "Name must be 'Hello'"
PS >     }
PS > }
PS > New-UDButton -Text "Validate form" -OnClick {
PS >     Test-UDForm -Id "form12"
PS > }

Test-UDForm|Creates a form with a validate button outside the form.
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/powershell-universal/it/comandi-powershell/new-udform.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
