Issue
- In some use cases, it may be desired for a form to branch into a path that does not require a form submission, based on the user's selection
- For example: If a user has submitted form in the past, they may not need to resubmit again
- Is this behavior possible through out-of-the-box forms and form rules?
Environment
- Liferay 7.4
Resolution
NOTE: The following resolution requires customization and should only be implemented at the discretion of your team. Liferay Support will not be able to assist with designing or implementing customizations.
- Currently, it is not possible to create a form path that does not require submission using out-of-the-box functionality
- However, this behavior may be accomplished by leveraging Liferay fragments that enables a selection that will redirect--appropriate to the selection
- Below is an example HTML fragment that demonstrates the following logic:
-
Page A -> Yes/No "form" selection (note: it is not a real form)
- No, will "jump" to page C (in this case, page are not Form pages but layouts).
- Yes, will "jump" to page B
- Page B -> Information
-
Page C -> Form
-
- NOTE: In this page, it may be beneficial to put some text before submitting: 'If you send this form you confirm "No" for the question ...." in case the user finds the form directly with the URL
-
- Example HTML code:
-
<select id="option" onchange="handleOptionChange()">
<option value="">Select an option</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<a id="infoLink" href="/pageB" style="display: none;"></a>
<a id="formLink" href="/pageC" style="display: none;"></a>
<script type="">
function handleOptionChange() {
const selectedOption = document.getElementById("option").value;
const infoLink = document.getElementById("infoLink");
const formLink = document.getElementById("formLink");
if (selectedOption === "yes") {
infoLink.click();
} else if (selectedOption === "no") {
formLink.click();
}
}
</script>
-
Page A -> Yes/No "form" selection (note: it is not a real form)
Additional Information