Init action and refresh page after form action

From the documentation: https://developer.wordpress.org/reference/hooks/init/ add_action( ‘init’, ‘process_post’ ); function process_post() { if( isset( $_POST[‘unique_hidden_field’] ) ) { // process $_POST data here } } In your example, perhaps having two different add_action is causing problems and burying your function where it’s not firing during init I’m going to test a similar solution and see what … Read more

How to properly refresh page after form action?

Searching around and not being able to implement the action through init hook I’ve found this workaround which for sure isn’t the best but does the job nicely. echo “<script type=”text/javascript”> window.location=document.location.href; </script>”; at the end of $_POST instructions. If somebody has a better solution, welcome to share.

Using $wpdb | checking entered email against existing emails in db

You shouldn’t be using mysql_num_rows() or mysql_error() when dealing with $wpdb. Even if you weren’t, mysql_error() is for database errors, and an empty result set is not a database error. If you want to know if results were returned, simply check the count() of the results: $duplicateEmail = $wpdb->get_results($emailTest, OBJECT); if ( count( $duplicateEmail ) … Read more

form action wordpress and php

If you’re using WordPress, you shouldn’t send POST requests directly to current URL. There is an API to process such requests. So how should that be done? First of all, you should send request to admin-ajax.php: So instead of this: <from action=”<?php get_permalink( $post->ID ) ?>” method=”POST” id=””> You should have this (also, there was … Read more

Contact Form 7 If Condition

Yes, you should be able access the form fields and field values with event.detail.inputs in addEventListener on wpcf7mailsent. You can then use the field values in the conditional statements and add the redirects you need. There’s a simple code sample in the plugin doumentation, https://contactform7.com/dom-events/, for looping the fields. EDIT Here’s a code example, document.addEventListener( … Read more

How to check form input against PHP variable?

Your problem is this bit: $input = $vCode That is not comparing the variables. It’s assigning the value of $vCode to $input. If you want to compare the two values, you need to use == or ===. $input == $vCode It still wouldn’t work though, because you haven’t actually defined $input. You’re only defining it … Read more