In edit form if we click save button it will take executeUpdate action of action.class.php file. But i want to call a customize executeUpdateSometing action function instead of executeUpdate action when user press the save button of the edit form. How can implement it?
There are several ways you can do this, but both rely in some changes to the routing.
Change Form Action
In the tag <form> there is action attribute <form action=""> which you can change to input a different route that points to your customised action for example:
<form id="my_form" method="POST" action="<?php echo url_for('#route_to_custom_update')?>">
//form fields go here
</form>
When the user clicks on the submit button this will then submit the form via the custom route which points to the customer update action.
Use jQuery
Create a jQuery (or JS) function that listens for the form submission action and then submits form via the custom route.
You can change the routing in the routing.yml file either by updating the existing route
update_form:
url: /update/url
param: { module: your_module, action: updatesomething}
or by adding a new route & using that in the form action or jQuery Ajax call
something_update_form:
url: /something/update/url
param: { module: your_module, action: updatesomething}
Note: that if you add another route the URL will need to be different from the existing update url.
The Symfony 1.4 documentation has more details on form submission & routing
Related
I am really hoping someone can help. Searched my heart out, but didn't seem to find anything on this.
What I want to do is:
User is in a page where cf7 is, and fills in details. I then redirect the user to a separate page using on_sent_ok: "location.replace('pageurl');"
How do I display the value of the user input name on the redirection page?
If you don't want to do any programming or need your client to be able to easily edit what is on each page of the form you can use the following plugin:
Contact Form 7 Multi-Step Forms
You can just add tags to the form builder that will separate pages. I chose this plugin because I wanted my client to be able to edit the form easily. If you use the code mentioned by purvik7373 you will need to make the updates to change form fields.
First change the on_sent_ok to:
on_sent_ok: 'my_custom_redirect();'
then create that my_custom_redirect() function in the page that displays the form:
<script>
function my_custom_redirect() {
var your_name = document.getElementById('YOUR_NAME_FIELD_ID').value; // get value from your input field (YOUR_NAME_FIELD_ID) id
var url = 'https://www.example.com/?name='+your_name+''; // your redirection url
window.location = url;
}
</script>
I'm trying to let users export data from the database to an excel file. I have a ProductController with a List action that receives information from search inputs. Like this:
[HttpGet]
public ActionResult List()
{
//Displays the view with a SearchForm element
return View();
}
[HttpPost]
public ActionResult List(FilterViewModel filter)
{
//Queries the database applying the filter
//and returns to the same view (it will output an html table now)
return View(databaseQueryResults);
}
My problem is that in order to download a file I want to apply the same filters selected on the List action. My View goes like this:
<form id="SearchProductForm" action="/Product/List" method="POST">
<!-- A few form controls go here in order to specify a criteria for searching -->
<input type="submit" value="Search" />
<button type="button">Export</button>
</form>
At this point my form has a submit button that will POST the form to the List method. However, when I press "Export" I need the form to be posted to a different action.
Sure, I can dinamically change the action method of my form but that doesn't seem the right way (or is it?).
The other option I can think of is to place my export button outside the form. But then I would need to have another form (a copy of my search form) so that it could be posted.
For all I know I can't start a download through Ajax. Or can I? If I could I would serialize the form and send to the second action.
So, how can I use one form for those two different situations in the best way possible?
Thanks for helping.
HI i want to add a button on a jsp page , which basically calls a method on a controller.
I know its possible to add a form and a button which makes submit:
<form:form name="info" method="POST" modelAttribute="form" >
<input type="submit" name="refresh" value="refresh"/>
</form:form>
Is there another way of doing this without, using the form tag?
Controller method will be invoked when incoming request has matching URI. So, basically you need to send a request with that matching URI. To avoid form tag
Create a <a> tag with that URI and render that tag as button using CSS, Which simplifies your job.
If page no need to refresh then make a AJAX call with same URI on clicking that button.
I have created a plugin, its adds an admin menu page for the menu. The page contains a form.
What I want to know is what is the suggested convention/method of handling form submissions.
Should I load the page and in that check for the $_POST ?
Should I load a separate form page ?
Thanks.
DETAILS:
The thought behind is:
I would want to load a new page and have my submit code it in, but would want to follow convention and the login/rules of capabilities.
(moved into wordpress.stackexchange.com)
You can use a form page into your plugin and when you load the page you check the $_POST like this
//At the page load
if( isset( $_POST["MyForm"]))
{
action();
}
//The Form
<form name="MyForm" method="POST" action="">
</form>
To load the new page if you have submit you have 2 solutions, in the "action()" you generate another page via PHP or you redirect to the other page you want but you have to register it to Wordpress unless you'll have an access denied.
Personnaly i suggest to generate your page into your plugin.
the default login form in drupal doesn't have any javascript to check whether the fields(Username and password) are empty or not before submitting the form.
so, i want to add it onsubmit to the user login form..how can i do that?
The best way would be to just create a module that adds a .js file (via drupal_add_js()) that does something like this (note: the classes here are just a guess, didn't check the actual class names):
$('.login-form .form-submit').click(function() {
// your error checking here
});
please read how to theme login block: http://drupal.org/node/19855
And attach to submit button one of these javascript functions:
http://www.tizag.com/javascriptT/javascriptform.php