Welcome Guest, Not a member yet? Register   Sign In
Forms, Binary characters and set_value
#1

[eluser]Unknown[/eluser]
So I have a database with some binary characters in it (smart quotes, emdashes, ellipses, etc) and I created a form to edit the database values. The database table and the webpages are all UTF-8 encoded. I load the database row for the edit form and do a mb_convert_encoding() call on any high-bit characters to convert from UTF-8 to HTML_ENTITIES.

So in my controller, I have code like this:
Code:
function edit( $id = NULL ) {
  $this->load->model( 'book_model', 'books' );
  $defaults = array();
  if ( $id ) {
    $defaults = $this->books->book_load( $id );
  }
  $this->load->view( 'admin/book_form', array( 'book' => $defaults ) );
}

And in my form view, I have a form field that looks like this:
Code:
<input type="text" name="title" value="<?php echo set_value( 'title', $book['title'] ); ?>" id="title" class="input-xxlarge" />

So the $defaults array has a value that looks like this: By the Author of “The Sketch-Book” and in the form field, it looks normal. However, when I add form validation to the mix, it appears the set_value() method getting called in the form view is double-encoding the value so I'm actually seeing the “ in the rendered HTML input box.

To me, this appears as a bug w/ the form validation's set_value call, but perhaps I'm approaching this incorrectly. Can someone point me in the right direction for how to handle binary characters in databases when putting together HTML forms w/ CodeIgniter?

Thanks in advance!

- Jason

PS: This is CodeIgniter version 2.1.3.




Theme © iAndrew 2016 - Forum software by © MyBB