Update of the SimpleForm example

MiServer is Dyalog's APL-based web development framework

Update of the SimpleForm example

Postby PGilbert on Mon Jul 27, 2020 9:10 pm

In v18, if you do the following:
      ⎕SE.SALT.Load 'HRUtils'


And define the function 'SimpleForm' as per paragraph 2.4 of HTMLRenderer User Guide:
      r←SimpleForm args;evt;html;req;resp;who
:If 0∊⍴args ⍝ Setup
html←'<title>A Simple Form</title>'
html,←'<form method="post" action="SimpleForm"><table>'
html,←'<tr><td>First: </td><td><input name="first"/></td></tr>'
html,←'<tr><td>Last: </td><td><input name="last"/></td></tr>'
html,←'<tr><td colspan="2"><button>Click Me</button></td></tr>'
html,←'</table></form>'
evt←'Event' 'HTTPRequest' 'SimpleForm'
'hr'⎕WC'HTMLRenderer'('HTML'html)('Coord' 'ScaledPixel')('Size'(200 400))evt
:Else ⍝ handle the callback
req←#.HRUtils.Request args ⍝ create a request from the callback args
who←req.Get¨'first' 'last' ⍝ retrieve from the form data
who←∊' ',¨who
req.Response.Content←'<h2>Welcome',who,'!</h2>' ⍝ set the content for the response
r←req.Respond ⍝ return the formatted response
:EndIf


and run the function you get the following error:

      SimpleForm ''
VALUE ERROR: Undefined name: Request
SimpleForm[11] req←#.HRUtils.Request args ⍝ create a request from the callback args


The method 'Request' does not exist in namespace 'HRUtils'. Would it be possible to get an updated version of the function 'SimpleForm' or is it the namespace 'HRUtils' that is outdated ?

Thanks in advance.
User avatar
PGilbert
 
Posts: 401
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Update of the SimpleForm example

Postby Brian|Dyalog on Tue Jul 28, 2020 6:14 pm

Hi Pierre,

Back in May, I wrote HRUtils.Request as a cover to create an instance of HRUtils.HttpRequest. I then dutifully updated the documentation to demonstrate that and then neglected to actually push my updated version of HRUtils to GitHub. I've now updated GitHub with the latest HRUtils.

There are a couple of ways to make the SimpleForm example work.
  • Change the line in SimpleForm from
          req←#.HRUtils.Request args ⍝ create a request from the callback args
    to
          req←⎕NEW #.HRUtils.HttpRequest args ⍝ create a request from the callback args
    This solution doesn't require you to update HRUtils.

  • Update HRUtils
    You can load the latest HRUtils from GitHub using HttpCommand.Fix
          ]load HttpCommand
    #.HttpCommand
    HttpCommand.Fix 'github.com/dyalog/library-conga/HRUtils.dyalog'
    0 #.HTUtils

    Or save the file from https://raw.githubusercontent.com/Dyalog/library-conga/master/HRUtils.dyalog and then ]load the downloaded file.

    This won't update HRUtils.dyalog installed in the /Library/Conga/ folder of your Dyalog installation, so, ]load HRUtils will still load the old one.

    You could save HRUtils.dyalog in the /Library/Conga/ folder of your Dyalog installation (on Windows and Mac you may need to do so as an administrator) or you can wait for an updated Dyalog installation image to be made available.

Personally, I'd recommend you modify SimpleForm to use ⎕NEW HRUtils.HttpRequest and wait for an updated Dyalog installation image.

I hope this helps!
/Brian
User avatar
Brian|Dyalog
 
Posts: 101
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: Update of the SimpleForm example

Postby PGilbert on Wed Jul 29, 2020 12:08 pm

Many thanks Brian, it's working now.
User avatar
PGilbert
 
Posts: 401
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada


Return to MiServer

Who is online

Users browsing this forum: No registered users and 1 guest