在简单页面上提交表单后如何获取变量值?

时间:2019-03-30 18:52:53

标签: octobercms

==
function onCheck()
{
   // It's simple page, not component, partial or controller
   // Therefore this syntax is right (according October docs)
   $this['myvar'] = "Hello";
}
==

<form class="dates" action="" method="POST" data-request="onCheck">
    <input type='text' class='date_inout' name="start" id='start'>
    <input type='text' class='date_inout' name="end" id='end'>
    <input type="submit" value="Подобрать">
</form>

<h1>{{ myvar }}</h1>

myvar未输出。我只需要在表单提交后获取myvar,而不需要onStartonInit

提前谢谢!

1 个答案:

答案 0 :(得分:0)

仅在ajax之后需要输出,然后您需要这样做

==
function onCheck()
{
   $dates = post('start') . ' - ' . post('end');
   return ['#myvarContsiner' => "Hello " . $dates];
   //         ^ this id
}
==

<form class="dates" action="" method="POST" data-request="onCheck">
    <input type='text' class='date_inout' name="start" id='start'>
    <input type='text' class='date_inout' name="end" id='end'>
    <input type="submit" value="Подобрать">
</form>

<h1 id="myvarContsiner"></h1>
<!-- this id ^ -->
  

现在,当您按下submit button时,它将转到onCheck并返回值['#myvarContsiner' => "Hello " . $dates],因此基本上"Hello " . $dates将根据<h1 id="myvarContsiner"></h1>中更新匹配的ID

和您的 将显示从onCheck

返回的值

如有疑问,请发表评论。