Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form error handling (saveForm method) #97

Open
cole007 opened this issue Sep 5, 2019 · 0 comments
Open

Form error handling (saveForm method) #97

cole007 opened this issue Sep 5, 2019 · 0 comments

Comments

@cole007
Copy link

cole007 commented Sep 5, 2019

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);
		}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant