Thursday, April 16, 2020

Under-depreciated

Oh, how I hate programming — and in particular programmers who decide that easy bits of code that anybody can use need to be depreciated (because "security") and replaced with nothing, requiring you to go hacking away in PHP at the core bits of your WordPress installation to achieve something you used to get with one line of code and should be built into a plug-in to begin with.

Take the simple act of having a "success page" after filling out a form. Any decent contact form program written since the dawn of the web would have this as an option — a page you go to after filling out a form that says, "Thank you." Easy enough, right?

Not in Contact Form 7. Oh sure, you used to be able to do this with one line of code:

on_sent_ok: "location = 'http://www.example.com/thank-you-page'";
But then someone decided, "Oh that's too easy, let's mess with people a bit." So now the process is considerably more complicated, namely editing the functions.php file in your WordPress installation to do exactly the same JavaScript thing, just in a way more likely to break things.



  1. add_action( 'wp_footer', 'redirect_cf7' );
  2.  
  3. function redirect_cf7() {
  4. ?>
  5. <script type="text/javascript">
  6. document.addEventListener( 'wpcf7mailsent', function( event ) {
  7.        location = 'https://www.example.com/thank-you/';
  8. }, false );
  9. </script>
  10. }

And again, it does exactly what the "old" method did, so aren't there still security concerns? No, I guess not. Because reasons.

And shouldn't this be built into the plug-in anyway? You know, one field called "success page" that you just fill out with a URL and be done with it? But no, things have to be difficult. And stupid.

https://www.rocketclicks.com/client-education/contact-form-7-thank-page-redirects/