简体   繁体   中英

Checking User inputs on formflow

Hi guys im using formflow, everything is working smoothly, i just have some small details that i need to fix.

  • Is there a way for me to check via regex the user inputs during the formflow? i need to check if the user inputs a valid name, email etc.
  • Can i change the confirmation before profile complete to a yes or no button instead of typing yes or no or y or n?

Below is the code

[Serializable]
public class ProfileForm
{
    [Prompt("What is your first name? {||}")]
    public string FirstName;
    [Prompt("What is your last name? {||}")]
    public string LastName;
    [Prompt("What is your email? {||}")]
    public string Email;

    public static IForm<ProfileForm> BuildForm()
    {
        return new FormBuilder<ProfileForm>()
                .Message("Welcome to the profile bot!")
                .OnCompletion(async (context, profileForm) =>
                {
                    // Tell the user that the form is complete
                    await context.PostAsync("Your profile is complete.");
                })
                .Build();
    }
}

So this hasn't been answered in a month so I hope by now you have found the answer yourself. If not, here is an easy way:

[Pattern(@"Put pattern here")]  
    public string Email; 

This way checks the string on input and will automatically request another try if it is incorrectly entered.

There are commonly used patterns for most of what you are looking for online. This post and this one are good at showcasing some of the ways to customise FormFlows. Hope this helps.

Edit. Sorry missed the second part of the question. To add a simple confirm button add this to your formflow:

.Confirm("Thanks, please can you confirm everything below is correct {*} {||}")

The "{*}" will show all the fields and the users response and the "{||}" will show the Yes/No buttons that you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM