RESTFUL form processing

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

RESTFUL form processing

tgiaccone


I'm trying to understand how to do form submissions to a restful web service in seaside. 

I've loaded up the restful support from seaside30addons

added these packages to the standard downloaded seaside image:

Seaside-Pharo-REST-Core-pmm.4.mcz
Seaside-REST-Core-pmm.23.mcz
Seaside-Tests-REST-Core-dkh.13.mcz

I rand the test cases and they all run fine.


My Html form looks like this:

<html>
<head>
</head>
<body>

<FORM action="http://localhost:8080/rest-example/addUser" method="post">
    <P>
    <LABEL for="firstname">First name: </LABEL>
              <INPUT type="text" id="firstname"><BR>
    <LABEL for="lastname">Last name: </LABEL>
              <INPUT type="text" id="lastname"><BR>
    <LABEL for="email">email: </LABEL>
              <INPUT type="text" id="email"><BR>
    <INPUT type="radio" name="sex" value="Male"> Male<BR>
    <INPUT type="radio" name="sex" value="Female"> Female<BR>
    <INPUT type="submit" value="Send"> <INPUT type="reset">
    </P>
 </FORM>

</body>


I enter data for each field in the form, set the radio box to "Male" and do the submit. 

I have a break point set in my method 

addUser
|aRequest postFields  |
<POST>
<Path: '/addUser'>
<Consumes: 'application/x-www-form-urlencoded'>
aRequest := self requestContext request.
postFields := aRequest postFields.
self halt.
Transcript show: 'Got it'; cr.

When inspected, postFields has exactly one element which is:

a WARequestFields('sex'->'Male')

Inspect the body and I get:

'sex=Male'

what happened to my form elements???


Tony




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: RESTFUL form processing

Philippe Marschall
2011/7/12 Tony Giaccone <[hidden email]>:

>
>
> I'm trying to understand how to do form submissions to a restful web service
> in seaside.
> I've loaded up the restful support from seaside30addons
> added these packages to the standard downloaded seaside image:
> Seaside-Pharo-REST-Core-pmm.4.mcz
> Seaside-REST-Core-pmm.23.mcz
> Seaside-Tests-REST-Core-dkh.13.mcz
> I rand the test cases and they all run fine.
>
>
> My Html form looks like this:
> <html>
> <head>
> </head>
> <body>
> <FORM action="http://localhost:8080/rest-example/addUser" method="post">
>     <P>
>     <LABEL for="firstname">First name: </LABEL>
>               <INPUT type="text" id="firstname"><BR>
>     <LABEL for="lastname">Last name: </LABEL>
>               <INPUT type="text" id="lastname"><BR>
>     <LABEL for="email">email: </LABEL>
>               <INPUT type="text" id="email"><BR>
>     <INPUT type="radio" name="sex" value="Male"> Male<BR>
>     <INPUT type="radio" name="sex" value="Female"> Female<BR>
>     <INPUT type="submit" value="Send"> <INPUT type="reset">
>     </P>
>  </FORM>
> </body>
>
> I enter data for each field in the form, set the radio box to "Male" and do
> the submit.
> I have a break point set in my method
> addUser
> |aRequest postFields  |
> <POST>
> <Path: '/addUser'>
> <Consumes: 'application/x-www-form-urlencoded'>
> aRequest := self requestContext request.
> postFields := aRequest postFields.
> self halt.
> Transcript show: 'Got it'; cr.
> When inspected, postFields has exactly one element which is:
> a WARequestFields('sex'->'Male')
> Inspect the body and I get:
> 'sex=Male'
> what happened to my form elements???

Have you tried adding name attributes?

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: RESTFUL form processing

tgiaccone
I'm not sure how to go about adding named attributes to a method that processes a form submission.

But beyond that I guess what I'm curious about is why out of all the elements in the form, the only one that made it to

self requestContext request.

is the radiobutton.  Why aren't the other entries there? Doesn't the request get parsed long before the REST classes
get involved?  Or am I missing something?


Tony

On Tue, Jul 12, 2011 at 3:15 PM, Philippe Marschall <[hidden email]> wrote:
2011/7/12 Tony Giaccone <[hidden email]>:
>
> When inspected, postFields has exactly one element which is:
> a WARequestFields('sex'->'Male')
> Inspect the body and I get:
> 'sex=Male'
> what happened to my form elements???

Have you tried adding name attributes?

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: RESTFUL form processing

tgiaccone
Ah, on closer examination of the form, I found my problem.

The elements have to have name attributes. Not Id

this form, where each INPUT tag has a "name" attribute works perfectly.

Tony


<FORM action="http://localhost:8080/rest-example/addUser" method="post">
    <P>
    <table>
      <tr>
       <td> <LABEL for="firstname">First name: </LABEL></td>
       <td> <INPUT type="text" name="firstname" ></td>
      </tr>
      <tr>
       <td><LABEL for="lastname">Last name: </LABEL></td>
       <td><INPUT type="text"  name="lastname"></td>
      </tr>
      <tr>
       <td><LABEL for="email">email: </LABEL></td>
       <td><INPUT type="text" name="email"></td>
      </tr>
           <td> &nbsp;</td>
       <td><INPUT type="radio" name="sex" value="Male"> Male</td>
      <tr>
       <td>&nbsp;</td>
       <td><INPUT type="radio" name="sex" value="Female"> Female</td>
      </tr>
      <tr>
        <td> <INPUT type="submit" value="Send"> </td>
        <td><INPUT type="reset"></td>
      </tr>
      </table>
 </FORM>


On Tue, Jul 12, 2011 at 3:52 PM, Tony Giaccone <[hidden email]> wrote:
I'm not sure how to go about adding named attributes to a method that processes a form submission.

But beyond that I guess what I'm curious about is why out of all the elements in the form, the only one that made it to

self requestContext request.

is the radiobutton.  Why aren't the other entries there? Doesn't the request get parsed long before the REST classes
get involved?  Or am I missing something?


Tony

On Tue, Jul 12, 2011 at 3:15 PM, Philippe Marschall <[hidden email]> wrote:
2011/7/12 Tony Giaccone <[hidden email]>:
>

> When inspected, postFields has exactly one element which is:
> a WARequestFields('sex'->'Male')
> Inspect the body and I get:
> 'sex=Male'
> what happened to my form elements???

Have you tried adding name attributes?

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: RESTFUL form processing

Philippe Marschall
In reply to this post by tgiaccone
2011/7/12 Tony Giaccone <[hidden email]>:
> I'm not sure how to go about adding named attributes to a method that
> processes a form submission.

Not the method, the html input element
name="theNameYouWantToSeeInTheRequestBody"

> But beyond that I guess what I'm curious about is why out of all the
> elements in the form, the only one that made it to

Because it was the only one with a name attribute?

> self requestContext request.
>
> is the radiobutton.  Why aren't the other entries there?

Because the browser didn't send them?

> Doesn't the request
> get parsed long before the REST classes
> get involved?  Or am I missing something?

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: RESTFUL form processing

tgiaccone
Yes, with a bit of investigation I had figured that out. It was obvious once I noticed that the name tag was missing. 

Foolish on my part. 

Tony

On Tue, Jul 12, 2011 at 4:14 PM, Philippe Marschall <[hidden email]> wrote:
2011/7/12 Tony Giaccone <[hidden email]>:
> I'm not sure how to go about adding named attributes to a method that
> processes a form submission.

Not the method, the html input element
name="theNameYouWantToSeeInTheRequestBody"

> But beyond that I guess what I'm curious about is why out of all the
> elements in the form, the only one that made it to

Because it was the only one with a name attribute?

> self requestContext request.
>
> is the radiobutton.  Why aren't the other entries there?

Because the browser didn't send them?

> Doesn't the request
> get parsed long before the REST classes
> get involved?  Or am I missing something?

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside