Skip to content

Commit

Permalink
Fixes handling of prepopulate data if there is a validation error whe…
Browse files Browse the repository at this point in the history
…n saving. Closes symphonycms#76
  • Loading branch information
Alistair Kearney committed Jul 30, 2009
1 parent 9c3abf6 commit df9962f
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions symphony/content/content.publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,18 +437,19 @@ public function __viewNew() {
if (isset($_REQUEST['prepopulate'])) {
$field_id = array_shift(array_keys($_REQUEST['prepopulate']));
$value = stripslashes(rawurldecode(array_shift($_REQUEST['prepopulate'])));

$this->Form->prependChild(Widget::Input(
"prepopulate[{$field_id}]",
rawurlencode($value),
'hidden'
));

if ($field = $entryManager->fieldManager->fetch($field_id)) {
// The actual pre-populating should only happen if there is not existing fields post data
if(!isset($_POST['fields']) && $field = $entryManager->fieldManager->fetch($field_id)) {
$entry->setData(
$field->get('id'),
$field->processRawFieldData($value, $error, true)
);

$this->Form->prependChild(Widget::Input(
'prepopulate',
"{$field_id}:" . rawurlencode($value),
'hidden'
));
}
}

Expand Down Expand Up @@ -563,8 +564,20 @@ function __actionNew(){
# Delegate: EntryPostCreate
# Description: Creation of an Entry. New Entry object is provided.
$this->_Parent->ExtensionManager->notifyMembers('EntryPostCreate', '/publish/new/', array('section' => $section, 'entry' => $entry, 'fields' => $fields));

redirect(URL . '/symphony/publish/'.$this->_context['section_handle'].'/edit/'. $entry->get('id') . '/created' . (isset($_POST['prepopulate']) ? ':' . $_POST['prepopulate'] : '') . '/');

$prepopulate_field_id = $prepopulate_value = NULL;
if(isset($_POST['prepopulate'])){
$prepopulate_field_id = array_shift(array_keys($_POST['prepopulate']));
$prepopulate_value = stripslashes(rawurldecode(array_shift($_POST['prepopulate'])));
}

redirect(sprintf(
'%s/symphony/publish/%s/edit/%d/created%s/',
URL,
$this->_context['section_handle'],
$entry->get('id'),
(!is_null($prepopulate_field_id) ? ":{$prepopulate_field_id}:{$prepopulate_value}" : NULL)
));

}

Expand Down

0 comments on commit df9962f

Please sign in to comment.