I have an URL. There is a form in that URL and I know it's name and the form action.
E.g:
url:
www.abc.com/123.html
form:
<form action="POST.php" method="post" name="form">
<input id="id" name="name" type="text">
</form>
My question is how do I post this form and get the response? I have tried several answers but they didn't work well. Any programming language is fine.
this can be done in PHP.
see this Submitting form to remote server.
Related
Please bear with me as the Rails guide chooses to not even mention the create action in their API section. My goal is to build a RESTFUL API from which content can be created. Here is what the form looks like after $ curl myapp
<form class="new_blog" id="new_blog" action="/blog" accept-charset="UTF-8" data-remote="true" method="post"><input name="utf8" type="hidden" value="✓" />
<label for="blog_input">Input a String</label>
<textarea class="input-field" name="blog[input]" id="blog_input">
</textarea>
<input type="submit" name="commit" value="Create Blog" />
</form>
I want to POST content through curl... or... can I test this somehow through Rspec?
The goal is that I have a RESTFUL API that allows content to be created through HTTP requests and then gives an HTTP response.
You can use Ruby HTTP Cheat Sheet and create various type of requests directly from Ruby, no need to go to curl for that.
I have simple paypal form to submit and make a payment inside in paypal. Once I saved user data, I want to initiate form submit action.
Here is a half solution - it posts data, but doesn't bring user on paypal checkout window as html form would do.
Submitting POST data from the controller in rails to another website
HTML form:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<INPUT TYPE="hidden" NAME="return" value="http://back">
<input type="hidden" name="cmd" value="_cart">
...
<input type="submit" >
</form>
So I need initiate submit button click from the controller with taking user to the same page where data has been posted, same as HTML form basically does.
Well, here's a link to a related question. To be short - you can't make a redirect + POST request in HTTP.
can some one help me please.
how can I add 1 more input to YUI POST CONNECTION
Here is the tutorial: http://developer.yahoo.com/yui/examples/connection/post.html
And the default sample form is: <form><input type="button" value="Send a POST Request" onClick="makeRequest();"></form>
How can I add one more input like that:
<form>
<input type="text" name="username">
<input type="button" value="Send a POST Request" onClick="makeRequest();">
</form>
I want to send username input request too.
Thank you !!
The example you reference builds the POST request body manually. While you can certainly do this, you might find it easier to use the setForm method of the Connection Manager (example here). It will include all the form fields and take care of the URL encoding for you.
I have the following form
<form id="file_upload" action="/Upload/Save" method="POST" enctype="multipart/form-data">
<input type="text" id="txtProposalName" name="name" placeholder="Nome da Camiseta" />
<input type="text" id="txtProposalDesc" name="description" placeholder="Descrição da Camiseta"/>
<div class="fileupload-buttonbar">
<div class="progressbar fileupload-progressbar"></div>
<span class="fileinput-button">
Upload images
<input type="file" name="files[]" multiple />
</span>
</div>
<input type="hidden" id="imgID" name="imgID"/>
<input type="submit" id="postProposal"/>
Would call this action:
[HttpPost]
public JsonResult Save(string name, string description, string imgID)
{
return Json("a");
}
(This is the current implementation, it has no logic because I am still testing some things).
My problem is: when I click on my submit button, the action is called with the correct values, but when it returns, my browser redirects to /Upload/Save (which is the action URL).
Why is this happening? Is there any way to prevent it?
Thanks!
You can use an asynchronous call to your method (e.g. AJAX) to prevent the page from reloading.
You can use Ajax.BeginForm to prevent reload page.
As I can see you use full page reload with:
action="/Upload/Save"
Also you trying to post data to json action method in controller. You need all form submit make with jquery, most problems you will find with ajax file uploaders.
Added:
Also look at serialize() it will help you to collect all form input values.
Dont need to prevent it, just redirect the user in your server code .
create a blank Rails application and put two files under public foler: file1.html and file2.html.
The contents of file is this
<h1>Post</h1>
<form action='/file2.html' class='openid' method='POST'>
<input name='openid_username' type='text' />
<input type='submit' value='Login' />
</form>
<h1>GET</h1>
<form action='/file2.html' class='openid' method='GET'>
<input name='openid_username' type='text' />
<input type='submit' value='Login' />
</form>
If I click on sumbit for the first form I get
No route matches "/file2.html" with {:method=>:post}):
When I do a get request it works fine. Why is that? I tried this with both webrick and mongrel and the behavior is same.
You need to setup a route to handle the post. If you run "rake routes" in the root of your project, it will give you a list of all of the routes currently setup and if it's a blank rails project then there will not be a route to handle the post to your file2.html ( although you don't really want to be posting to a static file in public, you should be posting to a controller ). The GET works because it is simply being treated as a static file fetch.
Try http://guides.rubyonrails.org/routing.html