PhixFlow Help
12. Validate Input
Validate input to your application to verify the content being provided. To recap the steps in the video:
Action Validation: Contact Number
Add an action to validate the data that users type in for new contacts.
- Open the
Contacts
stream. - Go to the section Actions, and add a new action.
- For the action, set:
- Name:
Validate Contact
- Display Name:
Validate Contact
Go to the Action Validation section.
Enter an expression to check that the phone numbers typed in contain only numbers or spaces.do ( if (!matches(_form.ContactNumber, "[0-9 ]+"), error("Invalid phone number") ) )
Raising an error in a validation expression - using the error() function will stop the action at that point. This means the data in the form will not be saved and any other tasks in the action, such as running task plans, will not go ahead.
- Go to the section Stream Item Action Rules.
- Add a Stream Item Action Rule.
- Add a Stream Action Item and set:
- Name:
Validate Contact
- Stream Item Action: Update
- Click Apply.
- Copy Values by Name: tick
- Name:
- Add a Stream Action Item and set:
- Save all your changes to the action
- Drag the action onto the Add button, and drag the Update button onto the
ContactManager
dashboard.
- Add a Stream Item Action Rule.
- Go to the section Stream Item Action Rules.
- Name:
Action Validation: Contact Name
We'll add some additional validation to check that the contacts names have been entered:
- Open the configuration form for the Action
Validate Contact
.
You can- either open the stream configuration form for
Contacts
and find the list of actions - or click on the
Add
orUpdate
button. From the button configuration form, follow the quick link to the action details.
- either open the stream configuration form for
- Add a condition to the Action Validation to check that the
FirstName
andFamilyName
are both set. - In the existing Action Validation statement, enter an expression to check that both names are provided.
if ( (isEmpty(_form.FirstName) || isEmpty(_form.FamilyName) ), error("Please complete both names for the contact") )
Save your changes and that completes the configuration. It is useful to see what is going on behind the scenes. Click on the Add
button in the configuration. You can see that by dragging the action onto the button, you have set the action for the button to Validate Contact
.
Go into App Mode. Type in a new contact and include an invalid character in the telephone number, for example, a letter. This should report an error. You can correct this, then save the new contact. Also test the contact name validation.
The final Action Validation should look like this:
do( // Validate the Contact Number if (!matches(_form.ContactNumber, "[0-9 ]+"), error("Invalid phone number") ), // Validate the Contact Names if ((isEmpty(_form.FirstName) || isEmpty(_form.FamilyName)), error("Please complete both names for the contact") ) )
Next video: 13. Data Types and Formatting
Please let us know if we could improve this page feedback@phixflow.com