【发布时间】:2014-03-19 10:41:57
【问题描述】:
我正在尝试在我的项目中上传视频文件。我在表单中包含表单验证,并且视频字段具有必需验证。问题是,即使我给出了所有值,表单也没有被提交。它显示错误为 The Video field is required(表单验证错误)。
控制器函数 - index():
function index()
{
$this->form_validation->set_rules('name', 'Name', 'required|trim|xss_clean|max_length[255]');
$this->form_validation->set_rules('video_type', 'Video genre', 'required');
$this->form_validation->set_rules('language', 'Language', 'required');
$this->form_validation->set_rules('length', 'Length', 'required|is_numeric');
$this->form_validation->set_rules('tralier', 'Tralier', 'is_numeric');
$this->form_validation->set_rules('link', 'Link', 'max_length[255]');
$this->form_validation->set_rules('thumb_image', 'Thumb Image', 'required|max_length[255]');
$this->form_validation->set_rules('video', 'Video', 'required');
$this->form_validation->set_rules('description', 'Description', 'required|xss_clean|max_length[500]');
$this->form_validation->set_rules('keywords', 'Keywords', '');
$this->form_validation->set_rules('accept_terms', '...', 'callback_accept_terms');
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
$genre=$this->db->query("select id,genre from genre where status=1 order by genre asc");
$data['genre']=$genre->result();
$language=$this->db->query("select id,language from movie_languages where status=1 order by language asc");
$data['language']=$language->result();
if ($this->form_validation->run() == FALSE) // validation hasn't been passed
{
$this->load->view('video/upload',$data);
}
else // passed validation proceed to post success logic
{
$form_data = array(
'title' => set_value('name'),
'genre' => set_value('video_type'),
'language' => set_value('language'),
'length' => set_value('length'),
'associatedvideo' => set_value('trailer'),
'videolink' => set_value('video'),
'videothumbnail' => set_value('thumb_image'),
'uploaderid' => set_value('1'),
'description' => set_value('description'),
'keywords' => set_value('keywords')
);
// run insert model to write data to db
echo $this->Video_model->SaveForm($form_data);
if ($this->Video_model->SaveForm($form_data) == TRUE) // the information has therefore been successfully saved in the db
{
redirect('video/success'); // or whatever logic needs to occur
}
else
{
echo 'An error occurred saving your information. Please try again later';
// Or whatever error handling is necessary
}
}
}
查看文件 - upload.php
<?php // Change the css classes to suit your needs
$this->load->view('layout/header');
$attributes = array('class' => '', 'id' => '');
echo form_open_multipart('video', $attributes); ?>
<table class="uploadtab">
<tr>
<td>
<label for="name">Name <span class="required">*</span></label>
</td>
<td>
<input id="name" type="text" name="name" maxlength="255" class="input" value="<?php echo set_value('name'); ?>" />
</td>
<td>
<?php echo form_error('name'); ?>
</td>
</tr>
<tr>
<td>
<label for="video_type">Video Genre <span class="required">*</span></label>
</td>
<td>
<?php
$array['']="Select";
foreach($genre as $row )
{
$array[$row->id] = $row->genre;
}
echo form_dropdown('video_type',$array, set_value('video_type'));
?>
</td>
<td>
<?php echo form_error('video_type'); ?>
</td>
</tr>
<tr>
<td>
<label for="category">Video Language <span class="required">*</span></label>
</td>
<td>
<?php
$langarray['']="Select";
foreach($language as $row )
{
$langarray[$row->id] = $row->language;
}
echo form_dropdown('language',$langarray, set_value('language'));
?>
</td>
<td>
<?php echo form_error('category'); ?>
</td>
</tr>
<tr>
<td>
<label for="length">Movie Length (in minutes)<span class="required">*</span></label>
</td>
<td>
<input id="length" type="text" name="length" class="input" value="<?php echo set_value('length'); ?>" />
</td>
<td>
<?php echo form_error('length'); ?>
</td>
</tr>
<tr>
<td>
<label for="tralier">Tralier</label>
</td>
<td>
<?php echo form_radio('trailer', '1', TRUE);?>Yes
<?php echo form_radio('trailer', '0');?>No
</td>
<td>
<?php echo form_error('trailer'); ?>
</td>
</tr>
<tr>
<td>
<label for="uploader_id">Upload Video <span class="required">*</span></label>
</td>
<td>
<input type="file" name="video" class="input" value="<?php echo set_value('video'); ?>" />
</td>
<td>
<?php echo form_error('video'); ?>
</td>
</tr>
<tr>
<td>
<label for="link">Link</label>
</td>
<td>
<input id="link" type="text" name="link" maxlength="255" class="input" value="<?php echo set_value('link'); ?>" />
</td>
<td>
<?php echo form_error('link'); ?>
</td>
</tr>
<tr>
<td>
<label for="thumb_image">Thumb Image <span class="required">*</span></label>
</td>
<td>
<input id="thumb_image" type="text" name="thumb_image" class="input" maxlength="255" value="<?php echo set_value('thumb_image'); ?>" />
</td>
<td>
<?php echo form_error('thumb_image'); ?>
</td>
</tr>
<tr>
<td>
<label for="description">Description <span class="required">*</span></label>
</td>
<td>
<?php echo form_textarea( array( 'name' => 'description', 'rows' => '8', 'cols' => '30', 'class'=>'textarea','value' => set_value('description') ) )?>
</td>
<td>
<?php echo form_error('description'); ?>
</td>
</tr>
<tr>
<td>
<label for="keywords">Keywords</label>
</td>
<td>
<input id="keywords" type="text" name="keywords" class="input" value="<?php echo set_value('keywords'); ?>" />
</td>
<td>
<?php echo form_error('keywords'); ?>
</td>
</tr>
<tr>
<td colspan="3">
<?php echo form_error('accept_terms'); ?>
<label class="checkbox"><input type="checkbox" name="accept_terms"><i></i>I agree to the Terms of Service</label>
</td>
</tr>
<tr>
<td>
<?php echo form_submit( 'submit', 'Submit'); ?>
</td>
</tr>
</table>
<?php echo form_close();
$this->load->view('layout/footer');?>
任何人都可以帮我找出表单未提交的问题。我没有收到任何文件类型/大小错误。
提前致谢。
【问题讨论】:
标签: php codeigniter file-upload