Codeigniter验证错误适用于不在服务器上的localhost

时间:2014-08-19 18:58:49

标签: codeigniter validation

我有问题在本地和服务器上运行相同的代码,但我在网上上传代码时没有得到验证错误。我通过flashdata传递validatio错误

Controller

function send_mail($lang)
    {     
        $this->load->library(array('email','form_validation'));

        $this->form_validation->set_rules('fullname', 'Full Name','trim|required|xss_clean');
        $this->form_validation->set_rules('address', 'Permanent Home Address', 'trim|required|xss_clean');
        $this->form_validation->set_rules('posta', 'Email Address', 'required|valid_email|xss_clean');
        $this->form_validation->set_rules('country', 'Country of Citizenship', 'trim|required|xss_clean');
        $this->form_validation->set_rules('date', 'Date of Birth','trim|required|xss_clean');
        $this->form_validation->set_rules('tel', 'Telephone Number','trim|required|xss_clean');
        $this->form_validation->set_rules('inst', 'Name of Institution','trim|required|xss_clean');
        $this->form_validation->set_rules('study', 'Field of Study',  'trim|required|xss_clean');
        $this->form_validation->set_rules('degree', 'Degree awarded/expected','trim|required|xss_clean');
        $this->form_validation->set_rules('dates1', 'Dates attended',  'trim|required|xss_clean');
        $this->form_validation->set_rules('dates2', 'Dates attended',  'trim|required|xss_clean');
        $this->form_validation->set_rules('employment', 'Employment',  'trim|required|xss_clean');
        $this->form_validation->set_rules('language', 'Language Skills',  'trim|required|xss_clean');
        $this->form_validation->set_rules('statement', 'Statement',  'trim|required|xss_clean');

            if($this->form_validation->run()==FALSE)
            {   

                $this->session->set_flashdata('errors', validation_errors());
                $this->set_fleshdata();
                header('Location: '.$_SERVER['HTTP_REFERER']);
            }
            else

在视图中

<?php
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$attributes = array('id' => 'intership_application_form',
                            'name' => 'intership',
                            );
echo $this->session->flashdata('success');
echo form_open_multipart('pages/send_mail/'.$lang, $attributes);
?>




                  <section>
                    <div > All fields required, only files in doc, docx or pdf format are allowed.</div><br/>
                    <div class="form_item">
                        <label class="form_item_name">Full Name:</label>
                        <input type="text" name="fullname"  placeholder="Full Name" value="<?php echo $this->session->flashdata('name'); ?>" >
                    </div><!--end .form_item-->

                    <div class="form_item">
                        <label class="form_item_name">Permanent Home Address:</label>
                        <input type="text" name="address" placeholder="Permanent Home Address" value="<?php echo $this->session->flashdata('address'); ?>"/>
                    </div><!--end .form_item-->

                    <div class="form_item">
                        <label class="form_item_name">Email Address:</label>
                        <input type="email" name="posta"  placeholder="Email Address" value="<?php echo $this->session->flashdata('posta'); ?>"/>
                    </div><!--end .form_item-->

                    <div class="form_item">
                        <label class="form_item_name">Country of Citizenship:</label>
                        <input type="text" name="country" placeholder="Country of Citizenship" value="<?php echo $this->session->flashdata('country'); ?>" />
                    </div><!--end .form_item-->

                    <div class="form_item">
                        <label class="form_item_name">Date of Birth:</label>
                        <input type="text" name="date"  placeholder="Date of Birth" value="<?php echo $this->session->flashdata('date'); ?>" />
                    </div><!--end .form_item-->

                    <div class="form_item">
                        <label class="form_item_name">Telephone Number:</label>
                        <input type="text" name="tel"  placeholder="Telephone Number" value="<?php echo $this->session->flashdata('tel'); ?>"/>
                    </div><!--end .form_item-->

                    </section>

                    <section>

                    <p><strong>University Level Education</strong>  <span>[ Please give details of your final school leaving qualification ]</span></p>

                    <div class="form_item">
                        <label class="form_item_name">Name of Institution:</label>
                        <input type="text" name="inst"  placeholder="Name of Institution" value="<?php echo $this->session->flashdata('inst') ?>"/>
                    </div><!--end .form_item-->

                    <div class="form_item">
                        <label class="form_item_name">Field of Study:</label>
                        <input type="text" name="study"  placeholder="Field of Study" value="<?php echo $this->session->flashdata('study'); ?>"/>
                    </div><!--end .form_item-->

                    <div class="form_item">
                        <label class="form_item_name">Degree awarded/expected:</label>
                        <input type="text" name="degree" placeholder="Degree awarded/expected" value="<?php echo $this->session->flashdata('degree'); ?>"/>
                    </div><!--end .form_item-->

                    <div class="form_item">
                        <label class="form_item_name">Dates attended:</label>
                        <input type="text" name="dates1" placeholder="Dates attended" value="<?php echo $this->session->flashdata('dates1'); ?>" />
                        <input class="below" type="text" name="dates2"  placeholder="Dates attended" value="<?php echo $this->session->flashdata('dates2'); ?>"/>
                    </div><!--end .form_item-->                   

                    </section>

                    <section class="third">
                        <div class="form_item">
                            <label class="form_item_name" />Employment<span>[ Please outline details of employment history or relevant professional experience ]</span></label>
                            <textarea  cols="" rows="" name="employment" placeholder="Your text here" ><?php echo $this->session->flashdata('employment'); ?></textarea>
                        </div>

                        <div class="form_item">
                            <label class="form_item_name" />Language SKills:<span>[ Proficiency in English is required for all CIRSD internship applicants, who are encouraged to indicate knowledge of any additional languages ]</span></label>
                            <textarea  cols="" rows="" name="language" placeholder="Your text here" ><?php echo $this->session->flashdata('language'); ?></textarea>
                        </div>


                    </section>

                    <section class="third">
                        <div class="form_item">
                            <label class="form_item_name">References:<span>[Please include three academic/professional references or letters of recommendation ]</span></label>
                            <div class="right">
                                <p>Please attach your reference here:</p>
                            <div class="upload_buttons">
                                  <p class="form">
                                    <input type="text" id="path" class="path" />
                                    <label class="add-photo-btn">BROWSE<span><input type="file" id="myfile" name='file1' /></span>
                                </label>
                                </p>    

                                  <p class="form">
                                    <input type="text" id="path1" class="path" />
                                    <label class="add-photo-btn">BROWSE<span><input type="file" id="myfile1" name='file2' /></span>
                                </label>
                                </p>

                                  <p class="form">
                                    <input type="text" id="path2" class="path" />
                                    <label class="add-photo-btn">BROWSE<span><input type="file" id="myfile2" name='file3' /></span>
                                </label>
                                </p>
                            </div><!--end .upload_buttons-->

                         </div><!--end .form_item-->
                    </section><!--end .third-->

                    <section class="third">
                        <div class="form_item">
                            <label class="form_item_name" />Personal Statement:<span>[ Compose a brief personal statement in English outlining your interests, why you are applying for the CIRSD internship program, and what you hope to gain from it. Include an explanation of what makes you a suitable candidate for an internship at CIRSD. All statements should not exceed the limit of 750 words ]</span></label>
                            <textarea name="statement" cols="" rows="" class="personal_statement" placeholder="Your text here"><?php echo $this->session->flashdata('statement'); ?></textarea>
                        </div>

                        <div class="form_item cv">
                            <label class="form_item_name" />Cirriculum Vitae:</label>

                            <div class="right cv">
                            <p class="form">
                                    <input type="text" id="path3" class="path cv"  value="Please attach your CV here:" />
                                    <label class="add-photo-btn">BROWSE<span><input type="file" id="myfile3" name='file4' multiple /></span>
                                </label>
                                </p>           
                            </div>             
                        </div>

                    </section><!--end .third-->


                    <section class="third">

                        <div class="form_item spam">
                            <label>Spam Check:</label>

                            <div class="spam_form">
                                <img src="<?php echo site_url(); ?>captcha_code_file.php?rand=<?php echo rand(); ?>" name="6_letters_code" id='captchaimg' >
                                <input type="text" class="spam_input"  name="6_letters_code"/>
                                <input type="submit" class="send_btn"  value="SEND" id="button"/>

                            </div>
                        </div><!--end .form_item-->


                    </section><!--end .third-->


<?php form_close(); ?>
   <div><?php var_dump($this->session->flashdata('errors'));?></div>

最后一行非常重要。奇怪为什么我的代码在xampp上不能在实时服务器上运行?

1 个答案:

答案 0 :(得分:0)

请检查您设置的代码&#39;错误&#39;用于设置错误消息的变量以及您正在访问的视图部分&#39;成功&#39;变量。请在两个地方使用相同的变量。

控制器:

$this->session->set_flashdata('errors', validation_errors());

查看:

echo $this->session->flashdata('success');

在控制器中使用此函数$ this-&gt; set_fleshdata();上面的方法(set_flashdata)足以设置你的flashdata。

同样在最后一行你忘了写回声&#39;在表格之前

<?php form_close(); ?> should be <?php echo form_close(); ?>