0

I want to create a dynamic question site, with some scroll, check, and whatever boxes. After the user send the form, i want to use the informations, to create dynamicly an answer. I tried a lot, but couldn't get it to work properly. So I hope, you may help.

get_event( 'Event_1', 1 ).
get_event( 'Event_2', 5).

get_component( 'Type_1', 'Component_1' ).
get_component( 'Type_2', 'Component_2' ).

get_incident( 'Incident_1' ).
get_incident( 'Incident_2' ).

index( Request ) :-
  reply_html_page(
    [
      title('Questions') 
    ],
    [
      form( [ id( search ), action(answer), method(post)], 
      [
        h1('All Questions'),
        div( [ h4('Question_1')
        |\selection ]),
        div( [ h4('Question_2') 
        |\component ]),
        div( [ h4('Question_3') 
        |\event ]),
        input( [ type( submit ), value( 'Submit' )])
      ])
    ]).

event -->
  { event( Ls ) },
  html( [ div( Ls )]).

event( Ls ) :-
  findall( span( [ input( [ value = Priority, name = Event, type = 'checkbox' ] ), Event ] ), get_event( Event, Priority ), Ls ).

component -->
  { component( Ls ) },
  html( [ div( Ls )]).

component( Ls ) :-
  findall( div( [ input( [ name = Component, value = [Type, ',', Component ], type = 'checkbox' ]), Component ]), get_component( Type, Component ), Ls ).

selection -->
  { selection( Ls ) },
  html( [ div( select( Ls ))]).

selection( Ls ) :-
  findall( option( [ name = Incident, value = Incident ], Incident ), get_incident(  Incident ), Ls ).

Now i want to use this information as post parameters. I found 2 solutions, http_parameters/3 and with member( method(post), Request)... , but wasn't able to bring it to work. How can i print all this parameters on a website?

HexXx
  • 252
  • 3
  • 8

1 Answers1

0

See e.g., http://www.swi-prolog.org/howto/http/HTMLParams.html for an example of handling parameters. The predicate http_parameters/3 processes both GET-requests and POST-requests, provided that the posted content is encoded as www-form-encoded (this is what a browser does for a form with method="POST"). You don't need a member(method(post), Request), unless you really want the handler to work only for POST requests. By default, it will work for both.

Jan Wielemaker
  • 1,670
  • 10
  • 18