• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with Form_Validation and Upload LIbraries

#1
[eluser]Sheikh Aman Alam[/eluser]
Hello.
i was wondering to know if there is a way to valida that-
a space wasn't put in the form field that has been posted.

i can use "alpha_dash", but i want to allow dot(.) and @ as well.

theres a segment in user guide that tells u can use php functions as validation function/rules too.
how to do that?


second thing, iam using upload library to upload images.
amazing library!
but is there any way to ignore the error if the user hasn't uploaded any image?
it makes the user to upload the image as a mandatory field, while that is not a requirement.

Please assist.

#2
[eluser]LuckyFella73[/eluser]
Hi,

Quote:i can use “alpha_dash”, but i want to allow dot(.) and @ as well.

In case you want to validate an email address you can use the
"valid_email" rule.
Otherwise you can write your own callback-functions additionally
to the build-in validation functions.
User Guide // Callback

About your file upload question:
Check if a file was selected for uploading like this:
Code:
if($_FILES['userfile']['size'])
{
     // do upload call
}

#3
[eluser]Sheikh Aman Alam[/eluser]
Thanks a lot for the link about callback functions.
it will work.
i'll try that soon.


Code:
if($_FILES['userfile']['size'])
{
     // do upload call
}

im using the 'upload' library of codeigniter, not PHP's core file upload mechanism,
i wanted to know in that.

#4
[eluser]LuckyFella73[/eluser]
Code:
if($_FILES['userfile']['size'])
{
     // do upload call
}

This line is just to check if a file was selected to upload.
If there is a file you go on with the codeigniter fileupload class!

A bit more detailed:
Code:
if($_FILES['userfile']['size'])
{
    // a file was selected so do the upload now
    // example from CI user guide:
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']    = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('upload_form', $error);
    }    
    else
    {
        $data = array('upload_data' => $this->upload->data());
        $this->load->view('upload_success', $data);
    }
}

#5
[eluser]Sheikh Aman Alam[/eluser]
ohk.. so u mean to say that the library doesn't provide any way of doing so, i'll have to use php's methods.

rest of it i already know.
Thanks for ur help dear!

#6
[eluser]LuckyFella73[/eluser]
You're welcome!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.