0

I need general guidance on how to structure a YESOD app. I would like to keep the app as "RESTful" in design as possible.

The user searches all the other users to find one to connect with. I show the possible connections using Hamlet:

  $forall (pid, person, mEmail, mPhone) <- displayPeopleRecs
    <p>
        <a href=@{CreateFundR pid}>#{personNickName person} 
           $maybe email <- mEmail
              #{emailEmail email}
           $maybe phone <- mPhone
              #{phoneNumber phone}

However, now when a user clicks on a link they go to the /createfund/ page as a GET request which is not what I want, I want to use POST or something else.

Can anyone explain what the correct solution is here? Do I make a form for each person what the search produces and have a submit button for each possible person? That seems silly. Is it better to use Julius and change the onclick handler for the link to submit a POST instead of a GET to /createfund ?

Here is the relevant line from my config/routes:

/createfund/#PersonId CreateFundR POST

By the way, I can see how to make this work by using a form and a submit button:

  $forall (pid, person, mEmail, mPhone) <- displayPeopleRecs
    <p>
      <form method="post" action="@{CreateFundR pid}">
        <table>
          <tr>
            <td>
              #{personNickName person} 
              $maybe email <- mEmail
                <br>
                #{emailEmail email}
              $maybe phone <- mPhone
                <br>
                #{phoneNumber phone}
            <td>
              <input type="submit" value="Create Fund">

That will work for my needs, but I'd really like to allow the user to just click the link. Is this poor design? Or just a matter of taste?

Tim Perry
  • 3,066
  • 1
  • 24
  • 40

1 Answers1

1

If you use an AForm / MForm, the form will be automatically generated for you (using Tables or Divs). That should simplify things for you.

If you want to manually style it, you can do something like this when using a form: How to make button look like a link?. Most people end up creating styled buttons for such actions anyways (think of your standard CRUD app with Edit, Delete buttons, etc.).

If you go down the path of trapping link clicks and do ajax Post, it will not degrade nicely if javascript is disabled so something you need to watch out for.

HTH

Community
  • 1
  • 1
Ecognium
  • 2,046
  • 1
  • 19
  • 35
  • I'm not to worried about people with javascript disabled. Javascript is a core piece of HTML5 and as long as following the link won't cause data to be deleted form the database (ie, doesn't send a DELETE) then I don't mind if they get a slightly poorer experience. I suppose I should be kind to people who work at a location that blocks javascript. Hmm. Thanks for the food for thought. – Tim Perry Jul 31 '13 at 22:09
  • Having read the post you linked to I'm going to use forms and style the buttons rather than make everything look like links. I got the UI designer to agree to a new standard. Thanks again. – Tim Perry Aug 01 '13 at 16:10