-
Notifications
You must be signed in to change notification settings - Fork 16
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
Submitting Form Causes Error #27
Comments
Hi @thezenmonkey, could you please provide the versions of SilverStripe core, userforms, elemental and elemental-userforms that you're using? |
I'm using SS4.1 and the most current versions of the other modules. First thing I did when I saw the problem was run an update to see if that was it. So Elemental 2.1.0 Elemental UserForms 1.0.0 Userforms 5.1.1 I should also mention the form is sitting in a an Elemental List block (dev-master). |
For clarification the issue only occurs when the form element inside a Elemental List block |
@thezenmonkey we ran into the same issue using virtual element blocks. Our forms are structured in a block page and referenced via virtual element for reuse. We also wanted to submit the forms via ajax so during post we sent the request to block page holder and this seemed to work well. Seems like the issue is nesting forms inside anything other then Elemental Block. @robbieaverill |
The same happens when putting the form in a jQuery-UI modal dialog. I’m trying to find a solution… |
Sorry for the noise. My issue with the $id not being found was due to querying the Elemental user form from another page. The form works as expected if shown in the page where it is attached, whether it is in a modal window or not. That said, there is another problem: the form is not working when another Elemental block is present in the page. But I’ll open another PR if I cannot find a solution. Thanks! |
Facing similar issue. Don't work
Works
I think the issue is in
Since $element is getting the elements directly from the owner, it actually doesn't look for more nested elements. Therefore, it can't find the element and returns the error. Changing |
I ran into this issue myself. I was trying to use an After doing a little digging, it looks like the reason this error is occurring is because when you're using an element ( The resolution for my case was to update the public function Form()
{
$controller = UserDefinedFormController::create($this);
$current = Controller::curr();
$controller->setRequest($current->getRequest());
if ($current && $current->getAction() === 'finished') {
return $controller->renderWith('App\Elements\ReceivedFormSubmission');
}
$owner_page = $this->owner->getPage();
$segment = $owner_page->URLSegment === RootURLController::get_homepage_link() ? 'home' : $owner_page->RelativeLink();
$form = $controller->Form();
$form->setFormAction(
Controller::join_links(
$segment,
'element',
$this->owner->ID,
'Form'
)
);
return $form;
} You'll see there's a little bit of logic to deal with the original |
@nathansams could you please create a PR for your update? |
Would the preference for a PR to have it against the 3 branch or 3.0? |
@nathansams I tried your solution and found that on submission, the "success" page was the page that the element was originally created on, not the page the virtual element sits on. Less of a problem, I also found that the userdefinedforms jquery validation only comes through for the ElementForm, not the virtualised ElementForm. |
Hi team, I had this same issue where I had a form inside of an element list and because currently public function handleElement()
{
$id = $this->owner->getRequest()->param('ID');
if (!$id) {
user_error('No element ID supplied', E_USER_ERROR);
return false;
}
/** @var SiteTree $elementOwner */
$elementOwner = $this->owner->data();
$elementalAreaRelations = $this->owner->getElementalRelations();
if (!$elementalAreaRelations) {
user_error(get_class($this->owner) . ' has no ElementalArea relationships', E_USER_ERROR);
return false;
}
foreach ($elementalAreaRelations as $elementalAreaRelation) {
$element = $this->findElement($elementOwner->$elementalAreaRelation()->Elements(), $id);
if ($element) {
return $element->getController();
}
}
user_error('Element $id not found for this page', E_USER_ERROR);
return false;
}
private function findElement($elements, $id)
{
$element = $elements->filter('ID', $id)->First();
if ($element) {
return $element;
}
foreach ($elements as $el) {
if (!$el->hasMethod('Elements')) {
continue;
}
$subElementAreaRelations = $el->getElementalRelations();
if (!$subElementAreaRelations) {
continue;
}
foreach ($subElementAreaRelations as $subElementalAreaRelation) {
$element = $this->findElement($el->$subElementalAreaRelation()->Elements(), $id);
if ($element) {
return $element;
}
}
}
return null;
} and then I also have to update the finished function of this modules - public function finished()
{
$user = $this->getUserFormController();
$user->finished();
$page = $this->getPage();
while(!$page instanceof SiteTree) {
$page = $page->getPage();
}
$controller = Injector::inst()->create($page->getControllerName(), $page->data());
$element = $this->element;
return $controller->customise([
'Content' => $element->renderWith($element->getRenderTemplates('_ReceivedFormSubmission')),
]);
} It seems to work fine..... |
For some context about the error itself, the actual error thrown is
It's thrown in The stack trace is
|
PRs merged. The relevant modules will be automatically tagged by GitHub actions |
I have a contact form built in a UserForm Element. Upon submitting ElementalContentControllerExtension throws a User Error. Element $id not found for this page.
The ElementalPageExtension is applied to sub class of Page (CustomPage) if the helps.
PRs
The text was updated successfully, but these errors were encountered: