-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify ElementForm to contain its’ own form builder.
- Loading branch information
Showing
5 changed files
with
101 additions
and
38 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace DNADesign\Elemental\UserForms\Control; | ||
|
||
use DNADesign\Elemental\Controllers\ElementController; | ||
use SilverStripe\Control\Controller; | ||
use SilverStripe\UserForms\Control\UserDefinedFormController; | ||
|
||
class ElementFormController extends ElementController | ||
{ | ||
public function __construct($element = null) | ||
{ | ||
parent::__construct($element); | ||
|
||
$current = Controller::curr(); | ||
|
||
if ($current->getRequest()->isPOST()) { | ||
// handle the post request. | ||
$user = UserDefinedFormController::create($element); | ||
$form = $user->Form(); | ||
|
||
$user->process($current->getRequest()->postVars(), $form); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace DNADesign\Elemental\UserForms\Model; | ||
|
||
use SilverStripe\UserForms\Control\UserDefinedFormController; | ||
use SilverStripe\UserForms\UserForm; | ||
use SilverStripe\Control\Controller; | ||
use DNADesign\Elemental\Models\BaseElement; | ||
use DNADesign\Elemental\UserForms\Control\ElementFormController; | ||
|
||
class ElementForm extends BaseElement | ||
{ | ||
use UserForm; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $table_name = 'ElementForm'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $title = 'Form'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $icon = 'elemental-userforms/images/form.svg'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $controller_class = ElementFormController::class; | ||
|
||
public function ElementForm() | ||
{ | ||
$controller = new UserDefinedFormController($this); | ||
$current = Controller::curr(); | ||
|
||
if ($current && $current->getAction() == 'finished') { | ||
return $controller->renderWith('ReceivedFormSubmission'); | ||
} | ||
|
||
$form = $controller->Form(); | ||
$form->setFormAction(Controller::join_links( | ||
$current->Link(), | ||
'element', | ||
$this->owner->ID | ||
)); | ||
|
||
return $form; | ||
} | ||
|
||
|
||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="elementform-form"> | ||
$ElementForm | ||
</div> |