Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot fill inputfield with string from database
    primarykey
    data
    text
    <p><strong>Update (on top because the post is so long)</strong></p> <p>Alright. New developments. When I add</p> <pre><code>resources.db.params.charset = "utf8" resources.db.params.driver_options.1002 = "SET NAMES utf8;" </code></pre> <p>to my bootstrap, the title is returned as <code>oriëntatie</code> (It's in the database as <code>oriëntatie</code>). But when I want to add <code>oriëntatie</code> to my DB, it gets stripped all the way down to <code>ori</code>.</p> <p><strong>Original post</strong></p> <p>I have built a CMS. Like any other CMS you can add/update pages.</p> <p>Now when I add a page with the a title containing, for example, the character <code>ë</code> it gets placed in the database as such in my title field. (I use StringTrim and StripTags filters on my form.)</p> <p>Now, when I want to update the page, and pre-fill the title input field I want to show the <code>ë</code> character again. Instead my input field remains empty.</p> <p>I tried to encode and decode the value (htmletities, html_entity_decode) all possible ways, but I can only get the htmlentity value displaying in the form field.</p> <p>My guts are telling me that this isn't the right way, but still I want people to add proper titles without spelling mistakes...</p> <p>Advice, tips anything would be greatly appreciated!</p> <p><strong>Edit: Added some code, not sure which parts</strong></p> <p>This is what happens with the code below:</p> <p>Adding the word <code>oriëntatie</code> through the input field puts <code>oriëntatie</code> in the database. While trying to load the value <code>oriëntatie</code> in the input field again on the update page, the input field stays empty. I now for sure that all the data is retrieved.</p> <p>Below is a screenshot of the database row filled.</p> <p><img src="https://i.stack.imgur.com/bo6n7.jpg" alt="enter image description here"></p> <p>Application.ini</p> <pre><code>resources.db.adapter = PDO_MYSQL resources.db.params.host = localhost resources.db.params.profiler = true </code></pre> <p>Bootstrap</p> <pre><code>// Build the view and layouts protected function _initBuildBase() { $this-&gt;bootstrap('view'); $this-&gt;bootstrap('layout'); $layout = $this-&gt;getResource('layout'); $this-&gt;view = $layout-&gt;getView(); $this-&gt;view-&gt;doctype("HTML4_STRICT"); $this-&gt;view-&gt;setEncoding('UTF-8'); $this-&gt;view-&gt;headMeta()-&gt;appendHttpEquiv('Content-Type', 'text/html;charset=utf-8'); $this-&gt;view-&gt;headMeta()-&gt;appendHttpEquiv('Content-Language', 'nl-NL'); $this-&gt;view-&gt;headMeta()-&gt;appendHttpEquiv('Cache-control', 'public'); $this-&gt;view-&gt;headMeta()-&gt;appendName('author', 'De Graaf &amp; Partners Communications'); } </code></pre> <p>Header of the update.phtml page</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;link href="/server_management/domains/cms_version_2/../../_application/public/images/admin/favicon.ico" rel="icon" type="image/x-icon" /&gt;&lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8" &gt; &lt;meta http-equiv="Content-Language" content="nl-NL" &gt; &lt;meta http-equiv="Cache-control" content="public" &gt; &lt;meta name="author" content="De Graaf &amp;amp; Partners Communications" &gt; &lt;meta name="robots" content="noindex, nofollow" &gt;&lt;link href="/server_management/domains/cms_version_2/../../_application/public/css/admin/style.css" media="screen" rel="stylesheet" type="text/css" &gt; &lt;!--[if IE]&gt; &lt;link href="/server_management/domains/cms_version_2/../../_application/public/css/admin/ie/style.css" media="screen, projection" rel="stylesheet" type="text/css" &gt;&lt;![endif]--&gt; &lt;!--[if IE]&gt; &lt;link href="/server_management/domains/cms_version_2/../../_application/public/css/blueprint/ie.css" media="screen, projection" rel="stylesheet" type="text/css" &gt;&lt;![endif]--&gt; &lt;link href="/server_management/domains/cms_version_2/../../_application/public/css/admin/print.css" media="print" rel="stylesheet" type="text/css" &gt;&lt;script type="text/javascript" src="/server_management/domains/cms_version_2/../../_application/public/jquery/jquery.lib.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/server_management/domains/cms_version_2/../../_application/public/jquery/jquery.loader.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/server_management/domains/cms_version_2/../../_application/public/jquery/jquery.init.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/server_management/domains/cms_version_2/../../_application/public/jquery/tinymce/jquery.tinymce.js"&gt;&lt;/script&gt;&lt;title&gt;Pages - Admin - DGPCMS&lt;/title&gt; &lt;/head&gt; &lt;body&gt; </code></pre> <p>Database</p> <p><img src="https://i.stack.imgur.com/oebki.jpg" alt="enter image description here"></p> <p>Database Table</p> <p><img src="https://i.stack.imgur.com/wZgwI.jpg" alt="enter image description here"></p> <p>PagesService (Insert and Update)</p> <pre><code>public function InsertPages($url, $parent_page, $title, $text, $keywords, $description, $user, $dashboardmessage) { $data = array( 'url' =&gt; $url, 'parent_page' =&gt; $parent_page, 'secure' =&gt; 'n', 'title' =&gt; $title, 'text' =&gt; $text, 'keywords' =&gt; $keywords, 'description' =&gt; $description, 'user_created' =&gt; $user, 'user_modified' =&gt; $user, 'date_created' =&gt; time(), 'date_modified' =&gt; time() ); return $this-&gt;pages-&gt;insert($data); $this-&gt;DashboardService-&gt;InsertDashboard('insert', 'pages', $dashboardmessage, $user); } public function UpdatePages($id, $url, $parent_page, $title, $text, $keywords, $description, $user, $dashboardmessage) { $data = array( 'url' =&gt; $url, 'parent_page' =&gt; $parent_page, 'secure' =&gt; 'n', 'title' =&gt; $title, 'text' =&gt; $text, 'keywords' =&gt; $keywords, 'description' =&gt; $description, 'user_modified' =&gt; $user, 'date_modified' =&gt; time() ); $this-&gt;pages-&gt;update($data, $this-&gt;CreateWhereClause($id)); $this-&gt;DashboardService-&gt;InsertDashboard('update', 'pages', $dashboardmessage, $user); } </code></pre> <p>PagesController (preDispatch, form settings)</p> <pre><code>$this-&gt;view-&gt;form = new Forms_Pages(); $this-&gt;view-&gt;form-&gt;setElementFilters(array('StringTrim', 'StripTags')); $this-&gt;view-&gt;standardform = new Forms_StandardButtons(); $this-&gt;view-&gt;standardform-&gt;setElementFilters(array('StringTrim', 'StripTags')); </code></pre> <p>PagesController (Insert and Update)</p> <pre><code>public function insertAction() { $this-&gt;view-&gt;pagesDropdown($this-&gt;PagesService-&gt;GetAllRootPages(), 'url'); $pass = false; $textArray = array(); foreach($this-&gt;PagesService-&gt;GetAllPages() as $result) { $textArray[] = $result-&gt;text; } if($this-&gt;getRequest()-&gt;isPost()) { if($this-&gt;view-&gt;form-&gt;isValid($this-&gt;getRequest()-&gt;getPost())) { if($this-&gt;checkexists-&gt;isValid($this-&gt;view-&gt;urlCleaner($this-&gt;view-&gt;form-&gt;getValue('title')))) { if(preg_match('/(\\[\\[news:overview\\]\\])/is', $this-&gt;view-&gt;form-&gt;getUnfilteredValue('text'))) { if(preg_grep('/(\\[\\[news:overview\\]\\])/is', $textArray)) { $this-&gt;_helper-&gt;flashMessenger(array('message' =&gt; $this-&gt;view-&gt;translate('The tag [[news:overview]] was already placed on another page. Please remove it before placing it on another page'), 'status' =&gt; 'notice')); } else { $pass = true; $this-&gt;cache-&gt;save($this-&gt;view-&gt;urlCleaner($this-&gt;view-&gt;form-&gt;getValue('title')), 'module_newsBasepage'); } } else { $pass = true; } if($pass) { $this-&gt;lastId = $this-&gt;PagesService-&gt;InsertPages( $this-&gt;view-&gt;urlCleaner($this-&gt;view-&gt;form-&gt;getValue('title')), $this-&gt;view-&gt;form-&gt;getValue('parent_page'), $this-&gt;view-&gt;form-&gt;getValue('title'), stripslashes($this-&gt;view-&gt;form-&gt;getUnfilteredValue('text')), $this-&gt;view-&gt;form-&gt;getValue('keywords'), $this-&gt;view-&gt;form-&gt;getValue('description'), $this-&gt;view-&gt;user-&gt;username, '&lt;strong&gt;'.$this-&gt;view-&gt;form-&gt;getValue('title').'&lt;/strong&gt;' ); $this-&gt;_helper-&gt;flashMessenger(array('message' =&gt; $this-&gt;view-&gt;translate('The '.$this-&gt;view-&gt;subject.' was succesfully saved'), 'status' =&gt; 'success')); if($this-&gt;getRequest()-&gt;getPost('save_finish') != 'Save') { $this-&gt;_redirect('/admin/pages/update/'.$this-&gt;lastId); } else { $this-&gt;_helper-&gt;redirectToIndex(); } } } else { $this-&gt;_helper-&gt;flashMessenger(array('message' =&gt; $this-&gt;view-&gt;translate('This '.$this-&gt;view-&gt;subject.' already exists'), 'status' =&gt; 'notice')); } } else { $this-&gt;_helper-&gt;flashMessenger(array('message' =&gt; $this-&gt;view-&gt;translate('Some errors occured'), 'status' =&gt; 'error')); } } } public function updateAction() { $this-&gt;view-&gt;result = $this-&gt;PagesService-&gt;GetSinglePage($this-&gt;_getParam('id')); $this-&gt;view-&gt;form-&gt;populate($this-&gt;view-&gt;result[0]); //$this-&gt;view-&gt;form-&gt;populate(array('title' =&gt; html_entity_decode($this-&gt;view-&gt;result[0]['title']))); $this-&gt;view-&gt;pagesDropdown($this-&gt;PagesService-&gt;GetAllRootPages(), 'url', $this-&gt;view-&gt;result[0]['title']); $pass = false; $textArray = array(); if($this-&gt;getRequest()-&gt;isPost()) { if($this-&gt;view-&gt;form-&gt;isValid($this-&gt;getRequest()-&gt;getPost())) { foreach($this-&gt;PagesService-&gt;GetAllPages() as $result) { if($result-&gt;id != $this-&gt;view-&gt;result[0]['id']) { $textArray[] = $result-&gt;text; } } if($this-&gt;view-&gt;form-&gt;getValue('title') != $this-&gt;view-&gt;result[0]['title']) { if($this-&gt;checkexists-&gt;isValid($this-&gt;view-&gt;urlCleaner($this-&gt;view-&gt;form-&gt;getValue('title')))) { $pass = true; } else { $this-&gt;_helper-&gt;flashMessenger(array('message' =&gt; $this-&gt;view-&gt;translate('This '.$this-&gt;view-&gt;subject.' already exists'), 'status' =&gt; 'notice')); } } if(preg_match('/(\\[\\[news:overview\\]\\])/is', $this-&gt;view-&gt;form-&gt;getUnfilteredValue('text'))) { if(preg_grep('/(\\[\\[news:overview\\]\\])/is', $textArray)) { $this-&gt;_helper-&gt;flashMessenger(array('message' =&gt; $this-&gt;view-&gt;translate('The tag [[news:overview]] was already placed on another page. Please remove it before placing it on another page'), 'status' =&gt; 'notice')); } else { $pass = true; $this-&gt;cache-&gt;save($this-&gt;view-&gt;urlCleaner($this-&gt;view-&gt;form-&gt;getValue('title')), 'module_newsBasepage'); } } else { $pass = true; } if($pass == true) { $this-&gt;lastId = $this-&gt;PagesService-&gt;UpdatePages( $this-&gt;_getParam('id'), $this-&gt;view-&gt;urlCleaner($this-&gt;view-&gt;form-&gt;getValue('title')), $this-&gt;view-&gt;form-&gt;getValue('parent_page'), $this-&gt;view-&gt;form-&gt;getValue('title'), stripslashes($this-&gt;view-&gt;form-&gt;getUnfilteredValue('text')), $this-&gt;view-&gt;form-&gt;getValue('keywords'), $this-&gt;view-&gt;form-&gt;getValue('description'), $this-&gt;view-&gt;user-&gt;username, '&lt;strong&gt;'.$this-&gt;view-&gt;form-&gt;getValue('title').'&lt;/strong&gt;' ); $this-&gt;_helper-&gt;flashMessenger(array('message' =&gt; $this-&gt;view-&gt;translate('The '.$this-&gt;view-&gt;subject.' was succesfully saved'), 'status' =&gt; 'success')); if(!$this-&gt;getRequest()-&gt;getPost('save_finish') != 'Save') { $this-&gt;_helper-&gt;redirectToIndex(); } else { $this-&gt;_redirect('/admin/pages/update/'.$this-&gt;_getParam('id')); } } } else { $this-&gt;_helper-&gt;flashMessenger(array('message' =&gt; $this-&gt;view-&gt;translate('Some errors occured'), 'status' =&gt; 'error')); } } } </code></pre> <p>This is the result of <code>Zend_Debug::dump($this-&gt;view-&gt;result);</code></p> <pre><code>array(1) { [0] =&gt; array(13) { ["id"] =&gt; string(3) "188" ["order"] =&gt; string(1) "0" ["url"] =&gt; string(10) "orientatie" ["parent_page"] =&gt; string(3) "n/a" ["secure"] =&gt; string(1) "n" ["title"] =&gt; string(10) "oriëntatie" ["text"] =&gt; string(13) "&lt;p&gt;Test 3&lt;/p&gt;" ["keywords"] =&gt; string(6) "Test 1" ["description"] =&gt; string(6) "Test 2" ["user_created"] =&gt; string(5) "Admin" ["user_modified"] =&gt; string(5) "Admin" ["date_created"] =&gt; string(10) "1326280122" ["date_modified"] =&gt; string(10) "1326280122" </code></pre> <p>And this is the html output</p> <pre><code>&lt;div class="padding_row"&gt; &lt;label for="title" class="required"&gt;Title&lt;/label&gt; &lt;input type="text" name="title" id="title" value="" class="form_validator"&gt; &lt;div class="form_validator_box"&gt; &lt;a href="#" title="This page already exists" class="form_validator_result_bad"&gt;&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload