Forums

Check for exisitng submitted form / data (voting)

jj135 31 Oct, 2019
Hi! We would like to create a voting form so visitors can vote for a project. The form itself will be pretty straightforward. We will be storing the data in a CMS database table.

What we would like to do is somehow check if someone already voted. Maybe by checking if a e-mail (an IP) are already stored in the table? Can this be done using CF?

Alternatively we could maybe place a cookie on the users computer to store a 'already voted' cookie and read this when opening a form? Users will ofcourse be able to simply delete their cookies and vote again. So that won;t be a very good 'protection' but it better then nothing ;-)

The best way would be to somehow e-mail the voter with and activation link. This link then 'activates' the stored vote. Could that also be done using CF? This way we know only voters with real email addresses can vote.

Any help or suggestions are also very welcome!

Kind regards,
Jip
jj135 31 Oct, 2019
How about this? Can this be done using CF and maybe some PHP?

jj135 31 Oct, 2019
Oeps. Three times the same image. Sorry....
jj135 31 Oct, 2019
Answer
Hi! I think I figured it out. And yes, it all seems possible ;-)

First I created an 'If' condition to check if the URL contains a variable to indicate the URL is meant for activation of a vote (?activationid=123)

If the URL is not an activation link: Show the form. This was not that easy, because the forms shows automatically. So I needed to a form area, and disable the 'Auto display view' in the Settings.

On form submit: First read the DB table (event) to find a match for the email field. If this returns a value (email found in table): Show a message saying voting is not possible. "E-mail already is used for voting." If e-mail is not yet present in the table, save the form data. I use an extra DB table field 'activation' with the value '0'. meaning the vote has not been activated yet. Then send an email using {var:data#.uid} in the link as a URL parameter. ([URL TO FORM]?activationid= {var:data#.uid}). The 'var' is the uid of the record in the database record that has been save by CF.

Now the voter receives the e-mail with the activation link. When clicked: Chronoforms uses the 'If' condition again to read the URL variable. Then the form is not shown, but a DB read event is first triggered. Using the uid from the URL parameter, (activationid) This time the read action tries to find the UID. If the record exists and is set to '0' a DB save (update) is performed to update 'activated' from 0 to 1. If the value is already set to '1' a message is shown that the vote has already been activated. If the record does not exist at all an error message is shown.

This seems to work!

If anyone has suggestions or maybe sees some pitfalls please let me know!

Maybe my post can help out someone in the future ;-)
This topic is locked and no more replies can be posted.