1

I've used Codeigniter for a while and whilst I've not always found the form validation as straightforward as I'm sure it should be I've never had any massive problems... until now!

I have a simple form comprised of text inputs and a textarea. The form starts off prepopulated and, if the validation fails, repopulates it with the last changed state.

My problem is this - The textarea needs to accept pound signs (£). It populates text from the database absolutely fine but on submit, whether the form validates or not, it strips them out, regardless of what I do!!

I've scoured the net and can only find solutions about applying things like htmlentities to the validation rules, but if I firephp the post data out, even before the rules, it's already been stripped out.

global_xss_filtering is set to false in my config.

It's driving me mad and wasting way more time than it should... has anyone got a solution to this, I know I'm probably missing something really simple - it's maddening!

Thanks,

Helen

Here's my validation code, although the firephp log at the top shows it to already be stripped out so I can't see how doing anything here will help... I've tried adding the various php function as it suggests HERE (codeigniter manual) but it makes no difference at all.

public function edit_entry2($entry_id, $page_id) {
    $this->firephp->log($_POST);
    $this->load->library('form_validation');
    $this->form_validation->set_rules('name', 'Name', 'required|max_length[255]');
    $this->form_validation->set_rules('address1', 'Address line 1', 'max_length[255]');
    $this->form_validation->set_rules('address2', 'Address line 2', 'max_length[255]');
    $this->form_validation->set_rules('address3', 'Address line 3', 'max_length[255]');
    $this->form_validation->set_rules('address4', 'Address line 4', 'max_length[255]');
    $this->form_validation->set_rules('county', 'County', 'required|max_length[255]');
    $this->form_validation->set_rules('post_code', 'Post Code', 'max_length[10]');
    $this->form_validation->set_rules('telephone1', 'Telephone 1', 'required|max_length[12]|is_natural');
    $this->form_validation->set_rules('telephone2', 'Telephone 2', 'max_length[12]|is_natural');
    $this->form_validation->set_rules('fax', 'Fax', 'max_length[12]|is_natural');
    $this->form_validation->set_rules('email', 'Email address', 'valid_email');
    $this->form_validation->set_rules('website', 'Website', 'max_length[255]');
    $this->form_validation->set_rules('rating_awards', 'Rating/Awards', 'max_length[255]');
    $this->form_validation->set_rules('description', 'Description', 'max_length[1000]');
    $this->form_validation->set_rules('categories[]', 'Categories', 'callback_categories_check');

    if ($this->form_validation->run() == FALSE)
    {
        $this->edit_entry($entry_id, $page_id);
    }
    else
    {
        $updated_entry = array('name'=>$_POST['name'], 'address1'=>$_POST['address1'], 'address2'=>$_POST['address2'], 'address3'=>$_POST['address3'], 'address4'=>$_POST['address4'], 'county'=>$_POST['county'], 'post_code'=>$_POST['post_code'], 'telephone1'=>$_POST['telephone1'], 'telephone2'=>$_POST['telephone2'], 'fax'=>$_POST['fax'], 'email'=>$_POST['email'], 'website'=>$_POST['website'], 'rating_awards'=>$_POST['rating_awards'], 'description'=>$_POST['description']);
        $this->tourism_catalogue_model->update_entry($entry_id, $updated_entry, $_POST['categories']);
        $this->index($page_id);
    }
}
Toto
  • 89,455
  • 62
  • 89
  • 125
Helen Danger Burns
  • 421
  • 2
  • 9
  • 28
  • Can you post your validation code? – Colin Brock Jan 25 '12 at 20:31
  • 1
    If there isn't a better solution to this, you could always put the `£` sign as a label just before the input. – Bojangles Jan 25 '12 at 20:32
  • Are you using utf-8 as your encoding? – swatkins Jan 25 '12 at 20:36
  • @Colin - there you go, hope that helps :) – Helen Danger Burns Jan 25 '12 at 20:39
  • @JamWaffles - They will be within a textarea - the user will enter them as part of a description so this doesn't really help I'm afraid. – Helen Danger Burns Jan 25 '12 at 20:41
  • @swatkins - My database is utf-8, where else might I check this? Sorry if that's a dum answer! – Helen Danger Burns Jan 25 '12 at 20:41
  • @HelenDangerBurns - In your html document, you should have something like this: `` – swatkins Jan 25 '12 at 20:44
  • @swatkins - ahh, yes of course, sorry. I have `` in the corresponding view. – Helen Danger Burns Jan 25 '12 at 20:49
  • @HelenDangerBurns - Not sure if this will help, but you might try adding an `accept-charset` attribute on the form tag -- [take a look at this answer from another SO question](http://stackoverflow.com/a/1372612/844726). – swatkins Jan 26 '12 at 02:24
  • @swatkins - tried this, makes no difference I'm afraid. Thanks though, still looking :( – Helen Danger Burns Jan 26 '12 at 10:20
  • I'm at a loss. Is there a publicly accessible version of this? – swatkins Jan 26 '12 at 15:17
  • @swatkins - No I'm afraid not. I have got a bit futher though - I noticed it accepted `$` fine so I change the `accept-charset` attribute to the form and set it to `ISO-8859-2` and it worked! except when the validation fails it repopulates it with £ which I can't seem to process out within the form or with any php function - any ideas? I really appreciate your help. – Helen Danger Burns Jan 26 '12 at 15:39
  • Not sure, you might take a look at this question: - http://stackoverflow.com/q/3483417/844726 – swatkins Jan 26 '12 at 15:59
  • @swatkins - Thanks for this... I've now got it all working except that it repopulates with `£` rather than the double decoded one. I just can't find a way to encode this ONLY when validation has failed. IF you encode it regardless it screws up when the validation hasn't failed. FRUSTRATED! – Helen Danger Burns Jan 26 '12 at 16:25
  • Do you know which validation rule is failing? If it only happens on a failed validation, then that would suggest that it's something in the validation rules. – swatkins Jan 26 '12 at 16:29
  • @swatkins - It's a user interface for part of a control panel, so the form validation is just there to make sure the minimum is filled in. It only fails if one of three fields are left empty and the validation is working fine. It's that I need this field to repopulate with the pound sign showing correctly that's the problem. Anyway. I've given up - I've wasted way too much time on this. I've simply printed out a message should the validation fail to explain why some of the characters may look strange and to ignore them. Not a solution that I like but it'll do for now. Thanks for your help. – Helen Danger Burns Jan 26 '12 at 16:55
  • Sorry we couldn't figure it out. Good luck! – swatkins Jan 26 '12 at 16:57

1 Answers1

0

You can use validation callbacks. So, when your validation rule is triggered, it will then fire a callback function that you could then use to strip out or inject the pound symbols as desired.

Form Validation Callbacks

Skittles
  • 2,866
  • 9
  • 31
  • 37