Using contact form for logging – misuse or not?
-
Hi,
Apologies if this isn’t the right place for my question, I was after an overview of the method, hence trying here, but please advise if I need to move/delete this. Thanks.
I have built something that works, so I am not fixing an issue as such, but would like a community view as to whether it is a decent solution.
Desired feature: I am running an e-learning site, I would like users to be to click ‘mark complete’ on each relevant post.
I have been using Sensei LMS, but find it too clunky for some lighter tasks.
Wpcomplete seems not to be supported anymore
https://www.ads-software.com/plugins/wpcomplete/
Similarly favorites:
https://en-gb.www.ads-software.com/plugins/favorites/As I don’t want to run into issues in the future switching systems, and users losing their progress, I want to get something I can adapt and continue.
Homemade solution.
Ninja forms + custom SQLI created a ninja contact form which invisibly collects user_id and post_id on the submission.
I append this form to all posts in relevant category.
On each page run a shortcode to display results of custom sql looking for current post_id in submissions: returns ‘to do’ for zero rows and ‘done’ for >0 rows.add_shortcode('done_shortcode', 'done_shortcode'); function done_shortcode( $atts ) { ? ? global $wpdb; $user_ID = get_current_user_id(); $current_post_id = get_the_ID(); $results = $wpdb->get_results(" SELECT case when count(*) = 0 then 'To Do' else 'Done ?' end as completion_state FROM wp_posts p where p.post_type='nf_sub' and p.id in (select post_id from wp_postmeta where meta_key='_form_id' and meta_value='2') and post_author = $user_ID ? and (select meta_value from wp_postmeta where post_id=p.id and meta_key='_field_296')=$current_post_id order by post_date desc ; ? ? "); ? ? // Start buffering ? ? ob_start(); ? ? // Loop ? ? foreach( $results as $result ){ echo '<em>' . $result->completion_state . '</em>'; ? ? } ? ? // Return output ? ? return ob_get_clean(); }
Am I crazy? Or is this a feasible solution if it works ( it does). Essentially a contact form adds a line to the database and sends an email, which is exactly all I need. or am I misusing it? Thank you
- The topic ‘Using contact form for logging – misuse or not?’ is closed to new replies.