PHP validation of two fields within a wordpress plugin form

Hello,

I need help adding php validation to two fields within a wordpress plugin form . Validation methods need to restrict users to allow only jpg, jpeg, png, gif in image file upload field. Validation for title input needs to check for a value. Submit button needs to prompt error/success messages upon user submission. The plugin we are trying to modify is User Submitted Posts, http://perishablepress.com/user-submitted-posts , we have configured the plugin to only use the image upload field and title field. The error that is happening is a user can submit a post without the image uploaded. Need a solution.

Please contact via reply, pm or AIM if further explanation is needed.
AIM: AceEye88

Thank you.

[php] /* File type validation */

// Default file-type restriction
if ( '' == $file_type_pattern )
	$file_type_pattern = 'jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv';

$file_type_pattern = trim( $file_type_pattern, '|' );
$file_type_pattern = '(' . $file_type_pattern . ')';
$file_type_pattern = '/\.' . $file_type_pattern . '$/i';

if ( ! preg_match( $file_type_pattern, $file['name'] ) ) {
	//Fle-type uploaded is not allowed. Output your error mesage
}[/php]

To check if user uploaded file or not use is_uploaded_file()
Reference : http://php.net/manual/en/function.is-uploaded-file.php

Could you post your current modified code? Would be much easier. :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service