Unescape Form Fields POST data as Helper methode

Moved escaping or sent POST data into the Helper class since it is the
same everywhere.
This commit is contained in:
colymba 2012-09-05 20:17:19 +03:00
parent 861d4128dc
commit e7c7239ada
3 changed files with 21 additions and 45 deletions

View File

@ -235,9 +235,26 @@ class GridFieldBulkEditingHelper {
return $formFieldsHTML; return $formFieldsHTML;
} }
/**
* Simple function that replace the 'record_XX_' off of the ID field name
* prefix needed since it was taken for a pageID if sent as is as well as fixing other things
*
* @param array $data
* @return array
*/
public static function unescapeFormFieldsPOSTData ( $requestVars ) public static function unescapeFormFieldsPOSTData ( $requestVars )
{ {
//@todo $return = array();
foreach( $requestVars as $key => $val)
{
$return[ preg_replace( '/record_(\d+)_(\w+)/i', '$2', $key) ] = $val;
}
if ( isset($return['url']) ) unset($return['url']);
if ( isset($return['cacheBuster']) ) unset($return['cacheBuster']);
return $return;
} }

View File

@ -335,7 +335,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
*/ */
public function update(SS_HTTPRequest $request) public function update(SS_HTTPRequest $request)
{ {
$data = $this->getParsedPostData($request->requestVars()); $data = GridFieldBulkEditingHelper::unescapeFormFieldsPOSTData($request->requestVars());
$record = DataObject::get_by_id($this->gridField->list->dataClass, $data['ID']); $record = DataObject::get_by_id($this->gridField->list->dataClass, $data['ID']);
foreach($data as $field => $value) foreach($data as $field => $value)
@ -361,7 +361,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
*/ */
public function cancel(SS_HTTPRequest $request) public function cancel(SS_HTTPRequest $request)
{ {
$data = $this->getParsedPostData($request->requestVars()); $data = GridFieldBulkEditingHelper::unescapeFormFieldsPOSTData($request->requestVars());
$return = array(); $return = array();
$recordClass = $this->gridField->list->dataClass; $recordClass = $this->gridField->list->dataClass;
@ -383,25 +383,6 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
return $response; return $response;
} }
/**
* Simple function that replace the 'record_XX_' off of the ID field name
* prefix needed since it was taken for a pageID if sent as is as well as fixing other things
*
* @param array $data
* @return array
*/
function getParsedPostData(array $data)
{
$return = array();
foreach( $data as $key => $val)
{
$return[ preg_replace( '/record_(\d+)_(\w+)/i', '$2', $key) ] = $val;
}
return $return;
}
/** /**
* Add a unique prefix to sensitive HTML attributes (ID, FOR, NAME) * Add a unique prefix to sensitive HTML attributes (ID, FOR, NAME)
* Fixes rendering issue (i.e. dropdown fields) and IDs being mistaken for page IDs * Fixes rendering issue (i.e. dropdown fields) and IDs being mistaken for page IDs

View File

@ -162,7 +162,7 @@ class GridFieldBulkManager_Request extends RequestHandler {
*/ */
public function update(SS_HTTPRequest $request) public function update(SS_HTTPRequest $request)
{ {
$data = $this->getParsedPostData($request->requestVars()); $data = GridFieldBulkEditingHelper::unescapeFormFieldsPOSTData($request->requestVars());
$record = DataObject::get_by_id($this->gridField->list->dataClass, $data['ID']); $record = DataObject::get_by_id($this->gridField->list->dataClass, $data['ID']);
foreach($data as $field => $value) foreach($data as $field => $value)
@ -234,28 +234,6 @@ class GridFieldBulkManager_Request extends RequestHandler {
return $recordList['records']; return $recordList['records'];
} }
/**
* Simple function that replace the 'record_XX_' off of the ID field name
* prefix needed since it was taken for a pageID if sent as is as well as fixing other things
*
* @param array $data
* @return array
*/
function getParsedPostData(array $data)
{
$return = array();
foreach( $data as $key => $val)
{
$return[ preg_replace( '/record_(\d+)_(\w+)/i', '$2', $key) ] = $val;
}
if ( isset($return['url']) ) unset($return['url']);
if ( isset($return['cacheBuster']) ) unset($return['cacheBuster']);
return $return;
}
/** /**
* Edited version of the GridFieldEditForm function * Edited version of the GridFieldEditForm function
* adds the 'Bulk Upload' at the end of the crums * adds the 'Bulk Upload' at the end of the crums