I need to clear the POST data ($request->getPostParameter()) so that if the user refreshes the page the data does not get resubmitted. How do I do this in symfony?
The general rule in symfony is to redirect (not forward) in a controller that accepts post data, and presumably writes to the database. You can this behaviour in the generated action.class.php when using generate-module
I needed to reload previously loaded page without redirect, because the request was sent by ajax... so I processed the form and then just changed method from POST to GET, which prevent form resubmittion, and then forwarded request to another controller. Here is the code:
$request = $this->get('request');
$request->setMethod('GET');
$response = $this->forward($controller, $params);
return $response;
Related
How Do I create a POST request with paw that is equal to a (jquery) ajax $.ajax({type: "POST", (...)});request?
I thought I could set the HTTP_X_REQUESTED_WITH to XMLHttpRequest but it does not work.
Whats the basic difference between an ajax/javascript POST and a regular POST from a form?
To simulate a POST request made via Ajax, what you need to do is to add an HTTP header:
X-Requested-With: XMLHttpRequest
Set the request method to POST
Enter the URL
Add the header mentioned above
Then enter the body in the Body tab, using the Form URL-Encoded mode:
When you are doing a post from a form, you are executing a submit event. In case you did not override the browser's default behavior for form submission at least for the case you are talking about, then the browser will execute it as an html post, which is a full postback. It sends the request and when the response arrives, it will be the new content of the page.
If you do a post with Javascript, then a request is sent and upon response, your callback will be executed, if existent.
I want to access some request parameters in an Orbeon form sent via post to this form. I tried to use the XPath expression xxf:get-request-parameter('task_id') within the form, but this only works when the parameter is attached to the url (e.g. orbeon/fr/Activiti/dokumentfreigabe/new?task_id=4711).
Since I do not want to send all parameters in the url (but via POST and SSL), I need a solution to access request parameters in an orbeon form sent as a POST-Parameter.
You can't access parameters sent to the form with a form POST with an XPath function. Could you use an HTTP header to pass this value, instead of a form POST? If it possible, then you could use xxf:get-request-header('your-header').
If the form POST is done by the browser, and not by another server-side app or filter or reverse proxy, then you obviously wouldn't be able to set the header directly from the browser. However, you could continue doing the form POST from the browser, and add a servlet filter that extracts the value, and sets the value of a header, so you can then read it with xxf:get-request-header('your-header').
what is the difference between Html.BeginForm() and Ajax.Beginform() in MVC3. I just want to know the scenarios where I can use Html.BeginForm() and where I can use Ajax.Beginform().
Ajax
Won't redirect the form even you do a RedirectAction().
Will perform save , update and any modification operations asynchronously.
Validate the Form using FormMethods - OnSubmit. So you are abort the Post
This creates a form that submits its values using an asynchronous ajax request. This allows a portion of the page to be update without requiring that the entire page be refreshed.
Html
Will redirect the form.
Will perform operations both Synchronously and Asynchronously (With some extra code and care).
Html.BeginForm will always use RouteTable to detrmine the action attribute value.
This will create a form on the page that submits its values to the server as a synchronous HTTP request, refreshing the entire page in the process.
Html.BeginForm() will create a form on the page that submits its values to the server as a synchronous HTTP request, refreshing the entire page in the process.
Ajax.BeginForm() creates a form that submits its values using an asynchronous ajax request. This allows a portion of the page to be update without requiring that the entire page be refreshed.
Html.BeginForm() will use simple posting on page, it means your page will be refreshed when you post your form.
when Ajax.BeginForm() will use ajax posting on page, it means your page will not be refreshed when you post your form.
#Html.BeginForm is used to post the data by full page refresh whereas #Ajax.BeginForm performs Post back function and allows some portion of Html to be reloaded rather than overall page refresh.
Here is my use case
I have a search model with two actions search_set and search_show.
1 - A user loads the home page which contains a search_form, rendered
via a partial (search_form).
2 - User does a search, and the request goes to search_set, the search
is saved and a redirect happens to search_show page which again
renders the search_form with the saved search preferences. This search
form is different than the one if step1, because it's a remote form
being submitted to the same action (search set)
3 - Now the user does another search, and the search form is submitted
via ajax to the search_set action. The search is saved and executed
and now I need to present the result via rjs templates (corresponding
to search_show). I am told that if the request is xhr then I can't
redirect to the search_show action? Is that right? If yes, how do I
handle this?
Here is my controller class
http://pastie.org/993460
Thanks
That's right. Either make the request non-XHR and redirect as normal, or you could try rendering the URL you want to redirect to as text or part of a JSON object which your AJAX request then uses to call document.location.href = [whatever] (but this seems hacky).
Right now what's happening is your XHR request is returning the result of the redirect, and not actually redirecting the page that made the XHR request.
How would I go about creating and posting a form POST request from inside some Rails code?
The use case I have is that I have received a form request, and I would like to forward this request on to a third party with my parameters intact.
I should add that I want to redirect the user out to the third party with the form too.
From ruby docs for Net::HTTP:
res = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'),
{'q'=>'ruby', 'max'=>'50'})
You could just pass params as the second arg, eg:
Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'), params)
redirect_to some_path
Also, don't forget to require the lib:
require 'net/http'
require 'uri'
You're going to have to do this via Javascript, as there is no way of redirecting a POST request (as per the HTTP/1.1 protocol).
You might be able to do it this way:
receive the post form the user
change whatever data you mean to
respond to the request with a form full of hidden fields
automatically post that form to the third party via javascript on dom-loaded
Alternatively:
set the form action to be the third party url
intercept the onsubmit event with js
change whatever data you need, either by simple client-side manipulation of the form
or, post an ajax request to your app to treat the data, and replace the fields you need with from the ajax response
with the data now massaged, let the form go through to the third party