Demonstrate viewing form submission data outside of the admin area.
The Community Awareness of Drugs site uses Ninja Forms for class registration. Registrations generate an email but managing the individual emails can be cumbersome so viewing Submissions in one location is easier. I wanted to make it even easier by customising the output to a format that the site maintainers would find useful.
Using the ID of a form I retrieved the fields and recorded the field key (an internal string for the field) and the field label (the front end string). I dropped the ‘submit‘ field as that doesn’t have any useful data. This gives me an array with data like ‘name‘ => ‘Your name‘ and ‘your_email‘ => ‘Your Email Address‘.
Next I go through the submissions for that form. For each submission I get its field values. This is an array with field keys (those retrieved earlier) and the submitted data. It also includes field keys with IDs e.g. ‘_field_21‘ => ‘email@example.com‘ (a duplicate of ‘email‘ => ‘firstname.lastname@example.org‘).
I created a html table with the field labels in the header and the submission data in the body.
|Damien CCemail@example.com||It is 8:55am.|
|Me Againfirstname.lastname@example.org||This is the short message.|
|My Nameemail@example.com||This is the message|
The script is designed to be run independent of WordPress (though the script must be on the same site). The Ninja Forms API could easily be used via a page template or shortcode. With a shortcode the form ID could be passed as a parameter.
I will likely use this on the Community Awareness of Drugs site and split the list into the various course dates. Then the site maintainers will be able to print the page to have a simple list of those registered for a specific course.