Thanks for your assistance.
I have implemented your suggestions in the following code:
MODEL
class PerformJoinForm extends CFormModel
{
public $stagename;
public $realname;
public $email;
public $picture;
public $file;
public $file_name;
public $profile;</span>
public $ageid;
public $hispeed;
public $hirescam;
public $verifyCode;
/**
* Declares the validation rules.
*/
public function rules()
{
return array(
// name, email and profile are required
array('realname, email, profile, ageid, hispeed, hirescam', 'required'),
// email has to be a valid email address
array('email', 'email'),
<span style='color: red'>array('file_name', 'file', 'types'=>'png, jpg', 'maxSize'=>100000),</span>
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),
);
}
VIEW
<?php echo CHtml::form(’’, ‘post’, array(‘enctype’ => ‘multipart/form-data’)); ?>
<div class="simple">
<?php echo CHtml::activeLabel($performjoin,'stage name'); ?>
<?php echo CHtml::activeTextField($performjoin,'stagename'); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabel($performjoin,'real name'); ?>
<?php echo CHtml::activeTextField($performjoin,'realname'); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabel($performjoin,'email'); ?>
<?php echo CHtml::activeTextField($performjoin,'email'); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabel($performjoin,'picture'); ?>
<?php echo CHtml::activeFileField($performjoin,‘file’); ?>
</div>
CONTROLLER
public function actionPerformJoin()
{
$performjoin=new PerformJoinForm;
if(isset($_POST['PerformJoinForm']))
{
$performjoin->attributes=$_POST['PerformJoinForm'];
$performjoin->file=CUploadedFile::getInstance($performjoin,‘file’);
if($performjoin->validate())
{
// save the picture file
<span style='color: red'>$performjoin->file->saveAs('new_performers/testmodel.jpg');</span>
// prepare the email
$headers="From: {$performjoin->email}\r\nReply-To: {$performjoin->email}";
$subject="Another WTC Performer Application";
$body="Stage Name: $performjoin->stagename\r\nReal Name: $performjoin->realname\r\nEmail: $performjoin->email\r\nPicture: $performjoin->file\r\nProfile: $performjoin->profile\r\nAge Documentation: $performjoin->ageid\r\nHi-Speed Connection: $performjoin->hispeed\r\nHi-Res Camera: $performjoin->hirescam\r\n";
mail(Yii::app()->params['adminEmail'],$subject,$body,$headers);
Yii::app()->user->setFlash('performjoin','<br /><br /><center>Thank you for sending us your application. We will respond as soon as possible.</center>');
$this->refresh();
}
}
$this->render('performjoin',array('performjoin'=>$performjoin));
}
When I go to test the form I am getting a validation error:
Please fix the following input errors:
File Name cannot be blank.
Can you spot anything I am doing wrong?