EDIT: I think I've worked something out. - This character - ’
- seems to be breaking it. If I use a 'regular' apostrophe ('
) it appears to work fine, if I replace every snazzy apostrophe in it with a regular one, it submits just fine. So, next question: why does that fancy apostrophe break CodeIgniter or PHP? I will presume this is a CI bug, but please correct me if I'm wrong. Anyway, here's the question I originally posted, I would still appreciate some insight into why this is happening and if there's much I can do about it:
I'm tearing my hair out over this one. This is completely bizarre and I simply cannot work it out.
Firstly, I have a basic form:
<?php $attributes = array('class' => 'form1'); $selected="";
echo form_open('admin/edit_page/'.$page->row('id'), $attributes); ?>
<div>
<?php echo form_error('title'); ?>
<label>Page Title:</label><input type="text" maxlength="100" name="title" value="<?php echo $page->row('title');?>" />
</div>
<div class="textarea">
<?php echo form_error('content'); ?>
<label>Page Content:</label><textarea name="content"><?php echo $page->row('content');?></textarea>
</div>
<div class="no">
<input type="submit" value="Submit"/>
</div>
</form>
Next, I have the corresponding CI function:
function edit_page($id)
{
$this->form_validation->set_rules('title', 'Title', 'trim|required|max_length[50]');
$this->form_validation->set_rules('content', 'Content', 'trim|required');
// If validation has failed...
if ($this->form_validation->run() == FALSE)
{
$data['page'] = $this->gallery_model->get_page($id);
$this->load->view('admin/header');
$this->load->view('admin/editpage', $data);
$this->load->view('admin/footer');
}
else // Validation successful
{
$title = $this->input->post('title');
$content = $this->input->post('content');
$this->gallery_model->edit_page($id, $title, $content);
redirect('admin');
}
}
All OK so far, yes? Here's where the crazy problem begins.
- I can 'manually' type in any data I like into the Content field. I click Submit, all works as expected - the database is updated with my new data, all is good in the world.
- I can copy and paste 15 paragraphs of Lorem Ipsum or whatever into the field just fine. Hit submit, hooray.
- However: - I am trying to copy-paste the content from the client's site, specifically this page: http://jeremywebbphotography.com/biog.php - I am updating his site since my web dev skills have improved much since then. Here's where things go weird - upon hitting save after copy-pasting that, the form reloads, I get the error "The Content field is required", and my copy-paste into the field disappears.
- If I run WebKit Inspector on Network mode and capture the form submission request, I can clearly see my copy-pasted text in the $_POST array...
- However, if I begin my
edit_page
function withdie("Content is ".$_POST['content']);
- IT HAS CLEARED ITSELF. The output literally says "Content is ". That's all. - The above works as expected with the
title
field - it only affects content. - I fathomed there might be some funny special characters or something causing this to happen in the copied contents (even though there isn't) - but if you copy-paste it, then delete everything up until the first word 'Biog', then submit (so you are literally submitting one line), the same thing still happens!.
WTF is going on?!
Things I have confirmed it is not:
- My browser (latest Chrome Dev on Mac OS X Snow Leopard - tried in Safari and Firefox, same problem)
- CI XSS Filtering or Security Sanitising - turned these all off, no luck
- CI Form Validation. I've turned it off as well.
- The data I'm submitting (kind of) - see final descriptive bullet point.
- Also tried running
htmlspecialchars
andhtmlentities
via the Form Validation rules, no cigar.
Thanks for your help. To clarify, here's a screenshot of how I'm copy-pasting it:
(Nothing complex there, right?) - and finally, a quick screenshot of the actual page output after submission (sorry about the CSS wonks, I'm working on it):