Constraining email address text answers to addresses in a csv database

What is the issue? Please be detailed.
I am asking respondents for the email address using a text question type. I want to ensure that this email address will match one already stored in our database (i.e. the emails we are sending the form to). How can I constrain the text answer such that it must match one of the emails in the attached emails.csv file?

I understand that essentially I am creating a select_one question, but I don't want to do this because I don't want respondents to be able to see all the other email due to privacy concerns.

What have you tried to fix the issue?
I am new to odk, and haven't found documentation on this specific issue. ChatGPT suggested a constraint: not(string-length(pulldata('alumni_emails', 'email', 'email', ${A101}))) = 0. When tested, this did not exclude anything I typed into the box, either correct or incorrect email addresses.

I also understand from getodk.org support that since my database is only 500 emails, I could use the instance('list_name')/root/item[filter expression]/desired_property format instead of `pull_data', but I've not found help on using this format as a constraint - just as a note or calculation.

Many thanks for your help in advance.

hi @gilly_bearman,

Welcome to ODK Forum, if you have a moment, feel free to introduce yourself here

I am assuming you would be sending "Public Link" to the respondents to fill out the Form. One approach to ensure that email address in the Form matches the respondent's email address is to prefill it. For example if your public link is https://myodk.example.com/-/single/form_id?st=the_secret then you can append &d[email]=respondent_one@gmail.com to the URL to pre-populate the email field in the Form.

So you would send unique link to each respondent and the link would include their email address.

Thanks,

Sadiq

4 Likes

You can use pulldata() in a calculate to see if the email is matched in the list, and then string-length() to see if there was something returned.

The example also uses translate() to change all letters to lowercase (you'll need to adjust all the emails in your list to lowercase as well) so that the user doesn't have to match the case exactly, and normalize-space() to remove and leading/ trailing white space. The assumption is that the emails only contain numbers and A-Z letters.

email_check.xlsx (9.1 KB)
email_list.csv (67 Bytes)

3 Likes

Immensely helpful, thank you both.