Skip to content

Commit

Permalink
Alternative fix for the profilefields
Browse files Browse the repository at this point in the history
Don't use the name as index as this leads to problems if the name
contains for example spaces.
  • Loading branch information
blackcoder87 committed May 14, 2017
1 parent 9b8743a commit 731e623
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 4 additions & 2 deletions application/modules/user/controllers/Panel.php
Expand Up @@ -81,7 +81,8 @@ public function profileAction()
];

foreach ($profileFields as $profileField) {
$post[$profileField->getName()] = trim($this->getRequest()->getPost($profileField->getName()));
$index = 'profileField'.$profileField->getId();
$post[$index] = trim($this->getRequest()->getPost($index));
}

$validation = Validation::create($post, [
Expand Down Expand Up @@ -111,10 +112,11 @@ public function profileAction()
$profilMapper->save($model);

foreach ($profileFields as $profileField) {
$index = 'profileField'.$profileField->getId();
$profileFieldsContent = new ProfileFieldContentModel();
$profileFieldsContent->setFieldId($profileField->getId());
$profileFieldsContent->setUserId($this->getUser()->getId());
$profileFieldsContent->setValue($post[$profileField->getName()]);
$profileFieldsContent->setValue($post[$index]);
$profileFieldsContentMapper->save($profileFieldsContent);
}

Expand Down
2 changes: 1 addition & 1 deletion application/modules/user/mappers/ProfileFields.php
Expand Up @@ -168,7 +168,7 @@ public function loadFromArray($profileFieldRow = [])
}

if (isset($profileFieldRow['name'])) {
$profileField->setName(str_replace(' ','-',$profileFieldRow['name']));
$profileField->setName($profileFieldRow['name']);
}

if (isset($profileFieldRow['type'])) {
Expand Down
Expand Up @@ -77,7 +77,7 @@ public function loadFromArray($profileFieldRow = [])
}

if (isset($profileFieldRow['name'])) {
$profileFieldTranslation->setName(str_replace(' ','-',$profileFieldRow['name']));
$profileFieldTranslation->setName($profileFieldRow['name']);
}

return $profileFieldTranslation;
Expand Down
7 changes: 4 additions & 3 deletions application/modules/user/views/panel/profile.php
Expand Up @@ -152,8 +152,9 @@ class="form-control"

if(!$profileField->getType()) :
$value = '';
if ($this->originalInput($profileField->getName()) != '') {
$value = $this->escape($this->originalInput($profileField->getName()));
$index = 'profileField'.$profileField->getId();
if ($this->originalInput($index) != '') {
$value = $this->escape($this->originalInput($index));
} else {
foreach($profileFieldsContent as $profileFieldContent) {
if($profileField->getId() == $profileFieldContent->getFieldId()) {
Expand All @@ -169,7 +170,7 @@ class="form-control"
<div class="col-lg-8">
<input type="text"
class="form-control"
name="<?=$this->escape($profileField->getName()) ?>"
name="<?=$index ?>"
placeholder="<?=$value ?>"
value="<?=$value ?>" />
</div>
Expand Down

0 comments on commit 731e623

Please sign in to comment.