【问题标题】:prolog use post parameter properlyprolog 正确使用 post 参数
【发布时间】:2014-07-13 08:12:17
【问题描述】:

我想创建一个动态问题网站,其中包含一些滚动、检查和任何框。 用户发送表单后,我想使用这些信息来动态创建答案。我尝试了很多,但无法使其正常工作。 所以我希望你能帮上忙。

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 ).

现在我想将此信息用作发布参数。 我找到了 2 个解决方案, http_parameters/3 和 with member( method(post), Request)... ,但无法使其发挥作用。 如何在网站上打印所有这些参数?

【问题讨论】:

    标签: html post parameters prolog swi-prolog


    【解决方案1】:

    请参阅 http://www.swi-prolog.org/howto/http/HTMLParams.html 以获取处理参数的示例。谓词 http_parameters/3 处理 GET 请求和 POST 请求,前提是发布的内容被编码为 www-form-encoded(这是浏览器对带有 method="POST" 的表单所做的事情)。您不需要member(method(post), Request),除非您真的希望处理程序仅适用于 POST 请求。默认情况下,它适用于两者。

    【讨论】:

      猜你喜欢
      • 2015-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      • 2019-05-07
      • 1970-01-01
      相关资源
      最近更新 更多