Formerly
Formerly copied to clipboard
Form error handling (saveForm method)
Experiencing issues with saving forms that feature duplicate handle. The user is not being redirect to the form with the relevant error message and worse is being thrown an error because the save method is not factoring in the possibility of a form save being false.
Tested and possible fix in controller:
if (!craft()->formerly_forms->saveForm($form))
{
$ok = false;
} else {
$existingQuestions = craft()->formerly_forms->getQuestionsByFormId($form->id, 'id');
$questionsToDelete = array_diff_key($existingQuestions, $questions);
foreach ($questionsToDelete as $question)
{
craft()->formerly_forms->deleteQuestion($question);
}
foreach ($questions as $question)
{
$question->formId = $form->id;
if (!craft()->formerly_forms->saveQuestion($question))
{
$ok = false;
break;
}
}
}
craft()->urlManager->setRouteVariables(array(
'form' => $form,
'questions' => $questions,
));
if (!$ok)
{
craft()->userSession->setError(Craft::t('Couldn’t save form.'));
} else {
craft()->userSession->setNotice(Craft::t('Form saved.'));
$this->redirectToPostedUrl($form);
}