[1]

robin chang
Guest
April 22nd, 2009 at 5:05 am

Hi, I was wondering if there was a widget or hack that could check if the post title or post body are similar to any already posted, and if so, send an error message back. I am using the TDO mini-form for posting.

Thank you!

Permalink | Quote

[2]

Morten
Guest
April 23rd, 2009 at 9:46 pm

Hi Robin
I’m also looking for a function there can do this on custom field like url and rss feed

Maybe this function can be used http://wordpress.org/support/topic/179920 unfortunately, just do not know how do that :-(

Permalink | Quote

[3]

toul
Guest
May 10th, 2009 at 5:52 pm

yep…this is what i am looking for too…i try to code a solution.

Permalink | Quote

[4]

Mark Cunningham
Guest
May 25th, 2009 at 2:34 pm

As a first step, you could create you’re own custom validation, see this topic.

The trick is then to get the code to test if that post title has already been submitted. Custom Fields are slightly different.

Take this code, put it in a php file with a unique name and upload it to your wp-content/plugins directory. It’ll create a new plugin. Once activated you’ll have a new widget called custom validation. Plonk it on the end of you’re form and voila, it wont’ allow a submission with a similar title to an existing submission (even one held in moderation).

<?php
/*
Plugin Name: My Custom Validation for TDO Mini Forms
Plugin URI: http://thedeadone.net/forum/?p=2814
Description: Blah
Version: 2
Author: Mark Cunningham
Author URI: http://thedeadone.net
*/

global $tdomf_widget_customvalidation;

function tdomf_init_widget_customvalidation() {
    if(class_exists('TDOMF_Widget')) {

      class TDOMF_WidgetCustomValidation extends TDOMF_Widget
      {
          function TDOMF_WidgetCustomValidation() {
              $this->enableValidate();
              // enableValidatePreview will enable validation on input on preview
              $this->enableValidatePreview();
              $this->setInternalName('customvalidation');
              $this->setDisplayName('My Custom Validation');
              $this->enableControl(false);
              $this->start();
          }

          function validate($args,$options,$preview) {
              global $wpdb;

              // $preview is a boolean indicating if this is being called
              // to validate a preview

              // $args are the inputs from the form
              extract($args);
              $output = '';

              // $content_title contains the inputted post title
              //
              $test_title = tdomf_protect_input($content_title);
              // we're going to use safe_name so as to avoid mismatches with
              // captials and spaces
              $test_title_safe = sanitize_title($test_title);

              // generate query
              //
              $query = "SELECT ID, post_title ";
              $query .= "FROM $wpdb->posts ";
              #$query .= "WHERE post_title = '$test_title' ";
              $query .= "WHERE post_name = '$test_title_safe' ";
              $query .= "ORDER BY ID DESC ";
              $results = $wpdb->get_results( $query );

              // process results (if any results we have a match)
              //
              if(!empty($results)) {
                 $output = "Sorry the title '$test_title' is very similar to an existing entry title!";
              }

              return $output;
          }
      }
    }
    $tdomf_widget_customvalidation = new TDOMF_WidgetCustomValidation();
}
add_action('plugins_loaded', 'tdomf_init_widget_customvalidation');

?>

Permalink | Quote

[5]

hinrichs
Guest
August 9th, 2009 at 6:47 pm

Hi Mark

How about Custom Fields, how do I do that?

Permalink | Quote

Advertisments

Join the Discussion