Submit nested forms in Thymeleaf - spring-mvc

I am developing a web application using spring boot, spring mvc and thymeleaf.
I have in template two nested forms with different action and two submit buttons as following:
<form name="form1" action="#" th:action="#{/action1}" method="post">
...
<form name="form2" action="#" th:action="#{/action2}" method="post">
...
<button type="submit" value="Import"/>
</form>
...
<button type="submit" value="Validate"/>
</form>
How to let button "Import" submit form2 not form1...??
Thank you.

You can not have nested forms because a form can not have another form as descendants. You can have many forms in a body not nested as you know. You can have one set for import and another set for remaining by sharing common backbean.
Please refer the link
4.10.3 The form element
Content model:
Flow content, but with no form element descendants.
<body> <form id="outer-form" class="form-horizontal form" th:action="#{/urlOuter}" th:object="${myBackBeanObject}" method="post">
<fieldset id="form-fieldset">
<button id="save" name="save" class="btn btn-primary">Outer Save</button>
</fieldset>
</form>
<form id="inner-form" class="form-horizontal form" th:action="#{/urlInner}" th:object="${myBackBeanObject}" method="post">
<fieldset id="form-fieldset">
<button id="save" name="save" class="btn btn-primary">inner Save</button>
</fieldset>
</form></body>

Related

Rewrite form in symfony

i want to rewrite this form below using form object of symfony 4 and twig.
<form class="navbar-form form-search pull-right">
<input id="search" type="text" class="input-medium search-query">
<button type="submit" class="btn">rechercher</button>
</form>
How to do that ?
Symfony have a very large documentation about its components, so this is Forms, take a tour ;)

how to button linked to a new page

I am using CodeIgnighter framework. In my view I want to change the page when I click the button.
I set the base_url correctly.
Insert
Modify
You can also do it like this :
<form action="imports/add_user">
<input type="submit" value="Insert">
</form>
<form action="imports/modify_user">
<input type="submit" value="Modify">
</form>

Form with GET action does not redirect page (relative paths?)

I am trying to follow the advice from this question, on how to make an input field act like a link.
I have setup the form, and setup the URL.
Yet, when I click the input fields, nothing happens. It does not redirect me, and there is no console errors.
Any ideas on how to make this work?
Rendered source:
<form action="/ads/edit" style="display:inline;" method="get">
<input onclick="_gaq.push(['_trackEvent', 'Frontpage_Top_SaleBtn', 'click'])" type="button" class="button_green_big" value="Sælg virksomhed" />
</form>
<form action="/ads/editbuy" style="display:inline;" method="get">
<input onclick="_gaq.push(['_trackEvent', 'Frontpage_Top_BuyBtn', 'click'])" type="button" class="button_green_big" value="Køb virksomhed" style="margin-left: 10px;" />
</form>
My ASP.NET MVC code that renders this:
<form action="#Url.Action("Edit","Ads")" style="display:inline;" method="get">
<input onclick="_gaq.push(['_trackEvent', 'Frontpage_Top_SaleBtn', 'click'])" type="button" class="button_green_big" value="Sælg virksomhed" />
</form>
<form action="#Url.Action("EditBuy","Ads")" style="display:inline;" method="get">
<input onclick="_gaq.push(['_trackEvent', 'Frontpage_Top_BuyBtn', 'click'])" type="button" class="button_green_big" value="Køb virksomhed" style="margin-left: 10px;" />
</form>
as noted in one of the answers to the question on which you are referring
<form action="http://google.com">
<input type="submit" value="Go to Google">
</form>
Set your inputs type to 'submit' instead of 'button'

Post form i themeplate Wordpress

I'm building a form to integrate in WordPress. How can i prevent the form from displaying start.php as an new single page when submitting?. I would like to stay in the startform div inside the template. Right now I'm shipped to a new start.php page?
I've tried to change the action to correct path to start.php but it's still same problem?
My file is start.php, I'm using this code to display it:
<div class="startform">
<?php get_template_part( 'start' )?>
<div>
The form is in start.php:
<form method="post" action="start.php">
<input type="submit" id="up_vote" name="vote" value="newmember" />
<input type="submit" id="down_vote" name="vote" value="oldmember" />
</form>
I found my solution by adding the insert script on same page instead of action="start"
<form method="post">
<input type="submit" id="up_vote" name="vote" value="newmember" />
<input type="submit" id="down_vote" name="vote" value="oldmember" />
</form>

Form Variable Becomes Part of Link to Web Page

We are hosting a PURL site and the variable is at the end: http://mywebpage.com/first.last
Now the client wants a static web page where you go and enter a first and last, then on submit it goes to out PURL site.
Tried this with straight html but it's not going to work. On to ASP.
New to ASP and I'm trying to have a form that has 2 fields, first, last in a link. Here is the form concept:
<form id="form1" name="form1" method="post">
<p>
<label for="1">First Name:</label>
<input type="text" name="first" id="first" />
<label for="2">Last Name:</label>
<input type="text" name="last" id="last" />
</p>
<p><input type="submit" name="3" id="3" onclick="window.open('http://mywebpage.com/first=val1&.&last=val2')"/>
</p>
</form>
Any help to put me on the right tracks would be extremely welcome at this point.
Thank you,
Ed
Try this:
<form id="form1" name="form1" method="GET" action="http://mywebpage.com/" >
Then do a normal submit without onclick and window.open.
action will submit form to that URL, and method="GET" will pass form parameters in a query string.

Resources