Wordpress Version: 2.7.1
TDO Mini Forms Version: 0.12.6
Operating System (if known): N/A
Webserver Software: N/A
Link to Website: http://
Error Message:
Copy and paste any error messages here
Hi
I have added my modified form for category selection and I want to preven adding new posts if the form is empty. How can I compare the form value to NULL end die an error if it\’s NULL. Which tdo form file do I have to edit?
Thanks
Well, I have too many categories on my blog, with subcategories as well. In order to make the category selection process simpler I created two related select boxes – one for main categories and one for subcategories. But there is one problem: when these boxes are empty and the category isn’t selected the posts is added in one default category. I want to change it add display some message to tell user choose the category instead of publishing the post. Which file should I change for it?
My feeling would be that you should create a new widget and implement a validation function that does the checks you need. This would be the cleanest solution but would require some knowledge of PHP and plugins in Wordpress as you’d need to encapsulate the widget in a plugin becuase otherwise it’d get overwritten when you do an automatic upgrade of TDOMF.
So what you can do is, create a file in your wp-content/plugins such as tdomf_customvalidation.php and give it these contents:
<?php
/*
Plugin Name: My Custom Validation for TDO Mini Forms
Plugin URI: http://thedeadone.net/forum/?p=2224
Description: Blah
Version: 1
Author: Mark Cunningham
Author URI: http://thedeadone.net
*/
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->start();
}
function validate($args,$options,$preview) {
// $preview is a boolean indicating if this is being called
// to validate a preview
// $args are the inputs from the form
extract($args);
$output = "";
// do you're validation here and if the input is invalid, set
// output to a message. If output is left empty, validation
// will have assumed to have passed
return $output;
}
}
// Create and start the widget
//
global $tdomf_widget_customvalidation;
function tdomf_init_widget_customvalidation() {
$tdomf_widget_customvalidation = new TDOMF_WidgetCustomValidation();
}
add_action('plugins_loaded', 'tdomf_init_widget_customvalidation');
}
?>
Now, hopefully, you should have a new plugin called "My Custom Validation for TDO Mini Forms". Enable it and it should add a widget to your selection of widgets to use on a form. Drag and drop it to end of the form. Now when the form is submitted, the validation function declared in the file will be called.
So now you can implement a proper clean validation routine for the form.
Hi Mark,
I tried installing the above, but got this:
“Installing Plugin from file: tdomf_customvalidation.php
Unpacking the plugin package
Incompatible archive: PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature
Installation Failed”
Do you have any idea how we can fix this? Thanks a lot!
osharara, how are you attempting to “install” the tdomf_customvalidation.php?
The only way to use the php file is to manually upload it, via ftp, to your website under wp-content/plugins. Don’t try the “install from file” form in Wordpress UI. This is intended for plugins downloaded from Wordpress.org. I guess you might be able to do it if you zip tdomf_customvalidation.php and then attempt to use the form, but I’m not sure tbh.
I tried it myself and I had to do a few modifications I’m afraid.
<?php
/*
Plugin Name: My Custom Validation for TDO Mini Forms
Plugin URI: http://thedeadone.net/forum/?p=2224
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) {
// $preview is a boolean indicating if this is being called
// to validate a preview
// $args are the inputs from the form
extract($args);
$output = "";
// do you're validation here and if the input is invalid, set
// output to a message. If output is left empty, validation
// will have assumed to have passed
return $output;
}
}
}
$tdomf_widget_customvalidation = new TDOMF_WidgetCustomValidation();
}
add_action('plugins_loaded', 'tdomf_init_widget_customvalidation');
?>
Try this version of the code. FTP up the php file to wp-content/plugins.
Mark, I ftped the .php to plug-ins but nothing appeared, it only showed up as a widget when I ftped the .php to the widgets folder of the tdo miniforms. When I add the widget to the form (it is called My Custom Validation), but there is no where to edit it, other than the .php itself I think? I have a custom field, which is a URL, and I want to make sure that it is not submitted twice in the database through the same form, can you show me how to do that?
Thanks!
I hope this is related. I’ve been looking at the file-upload widget and would like to use it for users to upload only images. The code seems to only check file extensions though, which doesn’t feel extensive enough as a security measure to me. Could you provide some guidance as to how(where) I could go about implementing something like this cleanly? Would it be similar to the example shown earlier?
Mark Cunningham said:
I tried it myself and I had to do a few modifications I’m afraid.
<?php
/*
Plugin Name: My Custom Validation for TDO Mini Forms
Plugin URI: http://thedeadone.net/forum/?p=2224
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) {
// $preview is a boolean indicating if this is being called
// to validate a preview// $args are the inputs from the form
extract($args);
$output = "";// do you're validation here and if the input is invalid, set
// output to a message. If output is left empty, validation
// will have assumed to have passedreturn $output;
}
}
}
$tdomf_widget_customvalidation = new TDOMF_WidgetCustomValidation();
}
add_action('plugins_loaded', 'tdomf_init_widget_customvalidation');?>
Try this version of the code. FTP up the php file to wp-content/plugins.
I don’t get it to work. My “test” validation rutine is:
mylink = get_post_meta($post_id,tdomfkey2, true);
$output = $mylink;
where tdomfkey2 are my key to custom field 2. But i never get any output!
I really need help! Please..
Mark Cunningham
Administrator
April 28th, 2009 at 11:25 am
I guess you’re doing some extensive hacking of TDOMF. What exactly are you trying to achieve?
If you really must hack the tdomf code, you can do it in tdomf-form-post.php (or tdomf-form-ajax.php) is one place or within include/tdomf-form.php and the function tdomf_create_post.
Permalink | Quote