I have a simple Sinatra app and I am trying to integrate Cappuccino
into it as an experiment. In the version of the Sinatra app with no
Cappuccino, there is a form with an action of "/data" and when you
submit the form, it takes you to the "localhost:4567/data" page and
displays the input from the form.
My question: If I can set the "action" of a html form, how would I set
the "action" of a CPTextField or CPURLRequest to make the app behave
the same way? Could I use - setHTTPBody: in the URL request?
here is part of the form markup:
<form action="/data" method="post" accept-charset="utf-8">
</form>
and here is some the code from my AppController.j file :
- (@action)buttonPressed:(id)sender
{
var request = [[CPURLRequest alloc] initWithURL:"http://localhost:
4567/data?input="+[input objectValue]];
[request setHTTPMethod:"POST"];
testConnection = [[CPURLConnection alloc] initWithRequest:request
delegate:self];
}
Thanks for your time,
Calvin
var request = [[CPURLRequest alloc] initWithURL:"http://localhost:4567/
data";
[request setHTTPMethod:"POST"];
[request setHTTPBody:"input=" + escape([input objectValue])];
[request setValue:"application/x-www-form-urlencoded"
forHTTPHeaderField:"Content-Type"];
testConnection = [[CPURLConnection alloc] initWithRequest:request
delegate:self];
if the request returns some information you can use it with the
following delegate:
- (void)connection:(CPURLConnection)aConnection didReceiveData:
(CPString)data
{
alert(data);
What Elias posted is the equivalent of a straight up html form:
<form action="http://localhost:4567/data" method="post">
<input type="text" name="input" value="my value" />
<button>Submit</button>
</form>