Passing variables between pages using UDInput

I am trying to figure out how to pass variables between pages using UDInput with no luck, Any ideas :sweat_smile:

here is the code i am working on to test the process:

Get-UDDashboard | Stop-UDDashboard

$Homepage = New-UDPage -Name "HomePage" -Content {
	New-UDRow {
		New-UDColumn -Size 4 -Content { }
		New-UdColumn -Size 4 -Content {
			New-UDInput -Title "User Name" -Endpoint {
				param ($NextPageTitle)
				$Cache:MyVariable = $NextPageTitle
				$VAR = "123"
				New-UDInputAction -RedirectUrl "P1"
			}
		}
		New-UDColumn -Size 4 -Content { }
	}
}

$P1 = New-UDPage -Name "P1" -Title "Par :$NextPageTitle ,cache variable is $Cache:MyVariable ,Var is $VAR" -Content {
	New-UDRow {
		New-UDColumn -Size 4 -Content { }
		New-UdColumn -Size 4 -Content {
			New-UDInput -Title "Enter Next Page Title" -Endpoint {
				param ($P1Var)
				New-UDInputAction -RedirectUrl "P2"
				
			}
		}
		New-UDColumn -Size 4 -Content { }
	}
}

$P2 = New-UDPage -Name "P2" -Title "$P1Var" -Icon home -Content {
	
	New-UDCard -Title "Variable from last page is $P1Var"
	
	
}


$Navigation = New-UDSideNav -None
$MyDashboard = New-UDDashboard -Title "Navigation" -Pages @($Homepage, $P2, $P1) -Navigation $Navigation
Start-UDDashboard -Port 80 -Dashboard $MyDashboard
$Chrome = Start-Process 'http://localhost'

I know this is a bit of a cop out, but recently I couldn’t figure something like this out, so I just outputted the variable from the input field to a text file. The text file was stored in the current IIS directory the site was running, and used the $User variable to test and create a folder then plonk the text file in that $User folder. Then I could read that text file from any of my other pages and use that to run other queries etc…Just a thought if you are banging your head against the wall on this.

The catch here is , how will you use this to run a script every time the other page loads.

an example of that is the following 2 dashboards which i need to get the name of the person then redirect to another dashboard , that happened but how can i execute a script on the initialization of the next page or dashboard for example to send OTP to the user based on the variable which outputted from the first dashboard then initialize this in the other dashboard.

$MyDashboard = New-UDDashboard -Title "FirstOne" -Content {
	
	New-UDRow {
		New-UDColumn -Size 4 -Content { }
		New-UdColumn -Size 4 -Content {
			New-UDInput -Title "Simple Form" -Id "Form" -Content {
				New-UDInputField -Type 'textbox' -Name 'Name' -Placeholder 'Name'
			} -Endpoint {
				param ($Name)
				$obj = [pscustomobject]@{
					Name = $Name
				}
				$obj | out-file -FilePath C:\temp\obj.txt
				New-UDInputAction -RedirectUrl "http://localhost:81"
			}
			
		}
		New-UDColumn -Size 4 -Content { }
	}
}
$MyDashboard1 = New-UDDashboard -Title "NewOne" -Content {
	
	New-UDCard -Title "New Card" -Text "Some Text"
	
}

Start-UDDashboard -Port 80 -Dashboard $MyDashboard
Start-UDDashboard -Port 81 -Dashboard $MyDashboard

Start-Process http://localhost

Hey @alaaelmahdy just want to confirm if you have read:- Unable to get Dynamic Pages working as this might answer your question…?

That actually works for me , i just created a login screen which is taking the username validate it and then send an OTP then pass the OTP to the next page then if the user enters the same OTP it redirect to the IIS dashboard which reauthorize the user using AD Group

That did the trick , thank you @psDevUK

one drawback for this is that the last page is refreshed in the background while or after refreshing causing the otp to be resent

so are you looking just to authenticate to Active Directory by doing this?

i figured out the problem and now it’s fine only one time OTP sms.

I am looking for Dual authentication using OTP and username in addition and the most important dynamic content based on the username.
if only authentication it would be easy as IIS made this possible using authorization roles and windows authentication.

:sweat_smile: now i need to pass the username to another dashboard which is it’s port is the OTP itself i am succeeding in this but the page doesn’t forward it keeps rotating but it need time to be figured out :wink:

Thank you for your help and support.