Skip to content

Commit

Permalink
Functions to quickly edit submissions on front-end
Browse files Browse the repository at this point in the history
  • Loading branch information
Hubert Prein committed May 4, 2016
1 parent d02ce48 commit fae0957
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
3 changes: 3 additions & 0 deletions templates/_display/templates/form.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
{% if form.redirectEntryId -%}
<input type="hidden" name="redirect" value="{{ form.getRedirectUrl() }}">
{% endif -%}
{% if element.id %}
<input type="hidden" name="submissionId" value="{{ element.id }}">
{% endif %}

{%- if antispam -%}
{{ antispam }}
Expand Down
55 changes: 53 additions & 2 deletions variables/AmFormsVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,66 @@ public function submissions($attributes = array())
/**
* Get a submission by its ID.
*
* @param int $id
* @param int $id
* @param bool $setAsActive [Optional] Set as active submission, for editing purposes.
*
* @return AmForms_SubmissionModel|null
*/
public function getSubmissionById($id)
public function getSubmissionById($id, $setAsActive = false)
{
if ($setAsActive) {
// Get the submission
$submission = $this->getSubmissionById($id);
if (! $submission) {
craft()->amForms->handleError(Craft::t('No submission exists with the ID “{id}”.', array('id' => $id)));
return false;
}

// Get the form
$form = $submission->getForm();
if (! $form) {
craft()->amForms->handleError(Craft::t('No form exists with the ID “{id}”.', array('id' => $submission->formId)));
return false;
}

// Set active submission
craft()->amForms_submissions->setActiveSubmission($submission);

return $submission;
}
return craft()->amForms_submissions->getSubmissionById($id);
}

/**
* Display a submission to edit and save it.
*
* @param int $id
*
* @return string
*/
public function displaySubmission($id)
{
// Get the submission
$submission = $this->getSubmissionById($id);
if (! $submission) {
craft()->amForms->handleError(Craft::t('No submission exists with the ID “{id}”.', array('id' => $id)));
return false;
}

// Get the form
$form = $submission->getForm();
if (! $form) {
craft()->amForms->handleError(Craft::t('No form exists with the ID “{id}”.', array('id' => $submission->formId)));
return false;
}

// Set active submission
craft()->amForms_submissions->setActiveSubmission($submission);

// Display the edit form!
return craft()->amForms_forms->displayForm($form);
}


// Form methods
// =========================================================================
Expand Down

0 comments on commit fae0957

Please sign in to comment.