Created
November 6, 2014 02:34
-
-
Save owldesign/dab355a633310d25cd4f to your computer and use it in GitHub Desktop.
FormBuilder_FieldsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Craft; | |
class FormBuilder_FieldsController extends BaseController | |
{ | |
protected $allowAnonymous = true; | |
// SAVE FIELD | |
public function actionSaveField() | |
{ | |
$this->requirePostRequest(); | |
$field = new FormBuilder_FieldModel(); | |
$field->id = craft()->request->getPost('fieldId'); | |
$field->name = craft()->request->getPost('name'); | |
$field->handle = craft()->request->getPost('handle'); | |
$field->instructions = craft()->request->getPost('instructions'); | |
$field->translatable = (bool) craft()->request->getPost('translatable'); | |
$field->type = craft()->request->getRequiredPost('type'); | |
$typeSettings = craft()->request->getPost('types'); | |
if (isset($typeSettings[$field->type])) | |
{ | |
$field->settings = $typeSettings[$field->type]; | |
} | |
if (craft()->formBuilder_fields->saveField($field)) | |
{ | |
craft()->userSession->setNotice(Craft::t('Field saved.')); | |
if (isset($_POST['redirect']) && mb_strpos($_POST['redirect'], '{fieldId}') !== false) | |
{ | |
craft()->deprecator->log('FormBuilder_FieldsController::saveField():fieldId_redirect', 'The {fieldId} token within the ‘redirect’ param on fields/saveField requests has been deprecated. Use {id} instead.'); | |
$_POST['redirect'] = str_replace('{fieldId}', '{id}', $_POST['redirect']); | |
} | |
$this->redirectToPostedUrl($field); | |
} | |
else | |
{ | |
craft()->userSession->setError(Craft::t('Field Not Saved.')); | |
} | |
// Send the field back to the template | |
craft()->urlManager->setRouteVariables(array( | |
'field' => $field | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment