How to pass an HTML widget's value from an HTML form to an Xquery in eXist-db?

会有一股神秘感。 提交于 2020-06-01 05:08:23

问题


In my intention this question represents an universalization of a specific issue indicated in a previous request: see related question (this is why I dare to send a second help request). I still cannot find an answer to the problem of how exacltly an html widget's value could be passed to an Xquery.

The specific widget is a textarea, added to an html form (not to an XForm!) by means of the external function, the code of which can be found within the mentioned related question. So, the relevant chunck of html code (once the function is been executed) is this:

  <form method="post" action="query_update_notabene.xq">
        <textarea id="my_textarea">loaded_text</textarea>
    <br>        
    <table border="0">
        <tr>                
           <td>
                <input type="submit" value="Salva nota">
            </td>
            <td style="width: 20px;"></td>
           <td>
                <input type="reset">
            </td>
       </tr>
    </table>
  </form>

In my "query_update_notabene.xq" I'm simply not able to get the textarea value, which corresponds to the text content (new or edited) to be saved back to the xml file. I have tried all the flavours that I could think of with regard to the following two possibilities:

let $nota_text := request:get-parameter("my_textarea","")

let $nota_text := request:get-data()

But nothing seems to be working, not even something like:

let $nota_text := request:get-data()/body/form/div[@id='main']/textarea[@id='my_textarea']/text()

Can anyone help?

Thanks

Alex


回答1:


As I have found the solution, I answer myself. As usual in programming one cannot use analogy, one must be perfectly precise! The error was to use "id" instead of "name" here:

<textarea id="my_textarea">loaded_text</textarea>

Which means, going back to the constructing Xquery, that the following:

<textarea id="my_textarea">{$my_content}</textarea> };

must be changed into:

<textarea name="my_textarea">{$my_content}</textarea> };

As a consequence, the Xquery can now grasp the textarea contents with a simple:

let $nota_text := request:get-parameter("my_textarea","")


来源:https://stackoverflow.com/questions/62018539/how-to-pass-an-html-widgets-value-from-an-html-form-to-an-xquery-in-exist-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!