Unable to populate input field with string from database

Refresh (above because the message has been taking so long)

Good. New developments. When i add

resources.db.params.charset = "utf8" resources.db.params.driver_options.1002 = "SET NAMES utf8;" 

in my bootstrap, the name is returned as oriëntatie (it is in the database as oriëntatie ). But when I want to add oriëntatie to my DB, it completely shuts down to ori .

Original post

I created a CMS. Like any other CMS, you can add / update pages.

Now, when I add a page with a heading containing, for example, the ë character, it is placed in the database as such in my heading field. (I use StringTrim and StripTags filters in my form.)

Now, when I want to refresh the page and pre-populate the header input field, I want to show the ë symbol again. Instead, the input field remains blank.

I tried to encode and decode the value (htmletities, html_entity_decode) in all possible ways, but I can only get the htmlentity value in the form field.

My courage tells me that this is the wrong way, but still I want people to add the correct names without spelling mistakes ...

Advice, hints anything would be greatly appreciated!

Edit: code added, not sure which parts

Here's what happens with the code below:

Adding the word oriëntatie through the input field places oriëntatie in the database. If you try to load the oriëntatie value into the input field again on the update page, the input field remains empty. Now I am sure that all data will be restored.

Below is a screenshot of the filled database row.

enter image description here

Application.ini

 resources.db.adapter = PDO_MYSQL resources.db.params.host = localhost resources.db.params.profiler = true 

Bootstrap

 // Build the view and layouts protected function _initBuildBase() { $this->bootstrap('view'); $this->bootstrap('layout'); $layout = $this->getResource('layout'); $this->view = $layout->getView(); $this->view->doctype("HTML4_STRICT"); $this->view->setEncoding('UTF-8'); $this->view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8'); $this->view->headMeta()->appendHttpEquiv('Content-Language', 'nl-NL'); $this->view->headMeta()->appendHttpEquiv('Cache-control', 'public'); $this->view->headMeta()->appendName('author', 'De Graaf & Partners Communications'); } 

Page header update.phtml

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <link href="/server_management/domains/cms_version_2/../../_application/public/images/admin/favicon.ico" rel="icon" type="image/x-icon" /><meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <meta http-equiv="Content-Language" content="nl-NL" > <meta http-equiv="Cache-control" content="public" > <meta name="author" content="De Graaf &amp; Partners Communications" > <meta name="robots" content="noindex, nofollow" ><link href="/server_management/domains/cms_version_2/../../_application/public/css/admin/style.css" media="screen" rel="stylesheet" type="text/css" > <!--[if IE]> <link href="/server_management/domains/cms_version_2/../../_application/public/css/admin/ie/style.css" media="screen, projection" rel="stylesheet" type="text/css" ><![endif]--> <!--[if IE]> <link href="/server_management/domains/cms_version_2/../../_application/public/css/blueprint/ie.css" media="screen, projection" rel="stylesheet" type="text/css" ><![endif]--> <link href="/server_management/domains/cms_version_2/../../_application/public/css/admin/print.css" media="print" rel="stylesheet" type="text/css" ><script type="text/javascript" src="/server_management/domains/cms_version_2/../../_application/public/jquery/jquery.lib.js"></script> <script type="text/javascript" src="/server_management/domains/cms_version_2/../../_application/public/jquery/jquery.loader.js"></script> <script type="text/javascript" src="/server_management/domains/cms_version_2/../../_application/public/jquery/jquery.init.js"></script> <script type="text/javascript" src="/server_management/domains/cms_version_2/../../_application/public/jquery/tinymce/jquery.tinymce.js"></script><title>Pages - Admin - DGPCMS</title> </head> <body> 

Database

enter image description here

Database table

enter image description here

PagesService (Insert and Update)

 public function InsertPages($url, $parent_page, $title, $text, $keywords, $description, $user, $dashboardmessage) { $data = array( 'url' => $url, 'parent_page' => $parent_page, 'secure' => 'n', 'title' => $title, 'text' => $text, 'keywords' => $keywords, 'description' => $description, 'user_created' => $user, 'user_modified' => $user, 'date_created' => time(), 'date_modified' => time() ); return $this->pages->insert($data); $this->DashboardService->InsertDashboard('insert', 'pages', $dashboardmessage, $user); } public function UpdatePages($id, $url, $parent_page, $title, $text, $keywords, $description, $user, $dashboardmessage) { $data = array( 'url' => $url, 'parent_page' => $parent_page, 'secure' => 'n', 'title' => $title, 'text' => $text, 'keywords' => $keywords, 'description' => $description, 'user_modified' => $user, 'date_modified' => time() ); $this->pages->update($data, $this->CreateWhereClause($id)); $this->DashboardService->InsertDashboard('update', 'pages', $dashboardmessage, $user); } 

PagesController (preDispatch, form settings)

 $this->view->form = new Forms_Pages(); $this->view->form->setElementFilters(array('StringTrim', 'StripTags')); $this->view->standardform = new Forms_StandardButtons(); $this->view->standardform->setElementFilters(array('StringTrim', 'StripTags')); 

PagesController (Insert and Update)

 public function insertAction() { $this->view->pagesDropdown($this->PagesService->GetAllRootPages(), 'url'); $pass = false; $textArray = array(); foreach($this->PagesService->GetAllPages() as $result) { $textArray[] = $result->text; } if($this->getRequest()->isPost()) { if($this->view->form->isValid($this->getRequest()->getPost())) { if($this->checkexists->isValid($this->view->urlCleaner($this->view->form->getValue('title')))) { if(preg_match('/(\\[\\[news:overview\\]\\])/is', $this->view->form->getUnfilteredValue('text'))) { if(preg_grep('/(\\[\\[news:overview\\]\\])/is', $textArray)) { $this->_helper->flashMessenger(array('message' => $this->view->translate('The tag [[news:overview]] was already placed on another page. Please remove it before placing it on another page'), 'status' => 'notice')); } else { $pass = true; $this->cache->save($this->view->urlCleaner($this->view->form->getValue('title')), 'module_newsBasepage'); } } else { $pass = true; } if($pass) { $this->lastId = $this->PagesService->InsertPages( $this->view->urlCleaner($this->view->form->getValue('title')), $this->view->form->getValue('parent_page'), $this->view->form->getValue('title'), stripslashes($this->view->form->getUnfilteredValue('text')), $this->view->form->getValue('keywords'), $this->view->form->getValue('description'), $this->view->user->username, '<strong>'.$this->view->form->getValue('title').'</strong>' ); $this->_helper->flashMessenger(array('message' => $this->view->translate('The '.$this->view->subject.' was succesfully saved'), 'status' => 'success')); if($this->getRequest()->getPost('save_finish') != 'Save') { $this->_redirect('/admin/pages/update/'.$this->lastId); } else { $this->_helper->redirectToIndex(); } } } else { $this->_helper->flashMessenger(array('message' => $this->view->translate('This '.$this->view->subject.' already exists'), 'status' => 'notice')); } } else { $this->_helper->flashMessenger(array('message' => $this->view->translate('Some errors occured'), 'status' => 'error')); } } } public function updateAction() { $this->view->result = $this->PagesService->GetSinglePage($this->_getParam('id')); $this->view->form->populate($this->view->result[0]); //$this->view->form->populate(array('title' => html_entity_decode($this->view->result[0]['title']))); $this->view->pagesDropdown($this->PagesService->GetAllRootPages(), 'url', $this->view->result[0]['title']); $pass = false; $textArray = array(); if($this->getRequest()->isPost()) { if($this->view->form->isValid($this->getRequest()->getPost())) { foreach($this->PagesService->GetAllPages() as $result) { if($result->id != $this->view->result[0]['id']) { $textArray[] = $result->text; } } if($this->view->form->getValue('title') != $this->view->result[0]['title']) { if($this->checkexists->isValid($this->view->urlCleaner($this->view->form->getValue('title')))) { $pass = true; } else { $this->_helper->flashMessenger(array('message' => $this->view->translate('This '.$this->view->subject.' already exists'), 'status' => 'notice')); } } if(preg_match('/(\\[\\[news:overview\\]\\])/is', $this->view->form->getUnfilteredValue('text'))) { if(preg_grep('/(\\[\\[news:overview\\]\\])/is', $textArray)) { $this->_helper->flashMessenger(array('message' => $this->view->translate('The tag [[news:overview]] was already placed on another page. Please remove it before placing it on another page'), 'status' => 'notice')); } else { $pass = true; $this->cache->save($this->view->urlCleaner($this->view->form->getValue('title')), 'module_newsBasepage'); } } else { $pass = true; } if($pass == true) { $this->lastId = $this->PagesService->UpdatePages( $this->_getParam('id'), $this->view->urlCleaner($this->view->form->getValue('title')), $this->view->form->getValue('parent_page'), $this->view->form->getValue('title'), stripslashes($this->view->form->getUnfilteredValue('text')), $this->view->form->getValue('keywords'), $this->view->form->getValue('description'), $this->view->user->username, '<strong>'.$this->view->form->getValue('title').'</strong>' ); $this->_helper->flashMessenger(array('message' => $this->view->translate('The '.$this->view->subject.' was succesfully saved'), 'status' => 'success')); if(!$this->getRequest()->getPost('save_finish') != 'Save') { $this->_helper->redirectToIndex(); } else { $this->_redirect('/admin/pages/update/'.$this->_getParam('id')); } } } else { $this->_helper->flashMessenger(array('message' => $this->view->translate('Some errors occured'), 'status' => 'error')); } } } 

This is the result of Zend_Debug::dump($this->view->result);

 array(1) { [0] => array(13) { ["id"] => string(3) "188" ["order"] => string(1) "0" ["url"] => string(10) "orientatie" ["parent_page"] => string(3) "n/a" ["secure"] => string(1) "n" ["title"] => string(10) "oriëntatie" ["text"] => string(13) "<p>Test 3</p>" ["keywords"] => string(6) "Test 1" ["description"] => string(6) "Test 2" ["user_created"] => string(5) "Admin" ["user_modified"] => string(5) "Admin" ["date_created"] => string(10) "1326280122" ["date_modified"] => string(10) "1326280122" 

And this is the html output

 <div class="padding_row"> <label for="title" class="required">Title</label> <input type="text" name="title" id="title" value="" class="form_validator"> <div class="form_validator_box"> <a href="#" title="This page already exists" class="form_validator_result_bad"></a> </div> </div> 
+6
source share
5 answers

I found a solution, and I can beat the crap out of myself for not thinking about it before and skipping it completely.

First solution:

In my .htaccess file, I had the AddDefaultCharset iso-8859-1 rule, which should have been AddDefaultCharset UTF-8

After a few days, I decided to consider the problem, leaving it alone for a few days (although during these days she listened to me). I looked at how to set the character encoding for the Zend application. All my settings were correct, agreed that I did not have an accept-charset for my form. So, after that I got the answer: or orïëntätïës .

The data was added to the database correctly, so I decided that utf-8_decode should be returned, and I was right. Now I knew for sure that another encoding was set up somewhere. I checked the utf8_decode description on php.net (link) and it called me:

utf8_decode - Convert a string with ISO-8859-1 characters encoded with UTF-8 to a single-byte ISO-8859-1

Then I searched in my full application for the string ISO-8859-1 , and the search returned what it was in my .htaccess file. So all I had to do was change this and everything was fine :)

0
source

The only time I saw this is when the client (browser) does not know the correct character encoding.

I see that you have added the appropriate HTTP Equiv meta to the HeadMeta , but are you really displaying it in your view or layout?

You should have something similar in the <head> section of your layout (or see if you are not using the layout)

 <head> <?php echo $this->headMeta() ?> 

I'm a little curious about your Bootstrap class. Could you show the rest of the code around the two lines you specified? Why is the view apparently a property of Bootstrap and how is it assigned?

+1
source

The dump shows the correct line. Therefore, this may not be a database problem.

But I noticed what you do

 $this->view->form->isValid($this->getRequest()->getPost()) 

AFTER FILLING () in your update action. The isValid method includes filling out the form already. So, here you can overwrite your line with an empty line from POST. You must move your populate () to

 if($this->getRequest()->isPost()) { //... } else{ // here } 

or delete it and replace isValid (...) with

 $this->view->form->isValid($this->view->result[0]) 

If the error is still elsewhere, insert

 Zend_Debug::dump($this->view->form->getValue('title')); 

after each main operation, to determine where your line changes to empty.

+1
source

Since the HTML page contains Content-Type text/html;charset=utf-8 , and the database has the correct sorting and encoding, then the problem should be in the application part.

The next possible problem may be related to the database, but since you installed "SET NAMES" utf8 "on the mySQL connection, the only logical next step will be the problem:

 $this->view->form->setElementFilters(array('StringTrim', 'StripTags')); 

Could you try to remove the StripTags from the filters so that you can check if there is a problem?

0
source

Maybe you are using this error? http://framework.zend.com/issues/browse/ZF-11533

0
source

Source: https://habr.com/ru/post/905616/


All Articles