Welcome Guest, Not a member yet? Register   Sign In
Validating File
#1

[eluser]Michael Wales[/eluser]
I've used this method before - I have no idea why it isn't working at the moment (maybe a change in 1.6.3?).

Anyone mind giving me a second look to see if they can determine why my callback function is not being called?

View:
Code:
<?php echo form_open_multipart('apply/' . $job->id, array('id'=>'apply')); ?>
    <fieldset>
        <legend>Your Information</legend>
        <p><label for="name">Your Name:</label><br />&lt;input type="text" name="name" id="name" maxlength="120" /&gt;&lt;/p>
        <p><label for="email">Your Email:</label><br /><span class="tip">Your email address will not be published and we'll never spam you.</span>&lt;input type="text" name="email" id="email" maxlength="120" /&gt;&lt;/p>
        <p><label for="cv">Cover Letter:</label><br />&lt;textarea name="cv" id="cv" cols="50" rows="10"&gt;&lt;/textarea></p>
    </fieldset>
    <fieldset>
        <legend>Upload Your Resume</legend>
        <p>&lt;input type="file" name="resume" id="resume" /&gt;
        <span class="tip">Accepted file formats are: DOC, PDF, RTF, and TXT.</span></p>
    </fieldset>
    <p>&lt;input type="submit" name="btnApply" id="btnApply" value="Send Application" /&gt; or &lt;?php echo anchor('job/' . $job->id . '/' . url_title($job->title), 'Cancel'); ?&gt;</p>
    &lt;input type="hidden" name="resume_v" /&gt;
&lt;?php echo form_close(); ?&gt;

Controller:
Code:
function apply($id = NULL) {
    // Make sure we have an ID to use
    if ($id === NULL) {
        redirect('');
        return;
    }
    // Validation
    $this->load->library('validation');
    $this->validation->validator('apply');
        
    // Get the data
    $this->data->job = $this->job->get_job($id);
        
    if ($this->validation->run()) {
        // TODO
    } else {
        $this->data->partial = 'jobs/apply';
        $this->load->view($this->layout, $this->data);
    }
}

Validator (I know this is being called, a die() within works perfectly) - this file's parent is MY_Validation, therefore the calls to methods within the Validation class you see here are valid.:
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed.');

$rules['name'] = 'trim|required';
$rules['email'] = 'trim|required|valid_email';
$rules['cv'] = 'trim|required';
$rules['resume_v'] = 'callback_check_resume';
$this->set_rules($rules);

$fields['name'] = 'Your name';
$fields['email'] = 'Your email address';
$fields['cv'] = 'Your cover letter';
$fields['resume_v'] = 'Your resume';
$this->set_fields($fields);

$this->set_error_delimiters('<li>', '</li>');

function check_resume($str) {
    die('test');
}

Anyone see what I am missing here?
#2

[eluser]Michael Wales[/eluser]
Okay... I'm retarded. I didn't notice until I wrote this post.

Quote:this file’s parent is MY_Validation, therefore the calls to methods within the Validation class you see here are valid

Therefore - my method check_resume belongs to the Validation class and the Validation class is looking for it to be within the Controller class.

Yay for more extending!
#3

[eluser]flojon[/eluser]
I think the callback function must be defined in your controller. Since it's called as
Code:
$this->CI->check_resume
See system/libraries/Validation.php around line 274.

EDIT: To late... :-)




Theme © iAndrew 2016 - Forum software by © MyBB