You may already be aware of this, but a better switch than the presence of
a parameter is to detect the request method. You could
call xdmp:get-request-method and know if the request is GET or POST, for
example:

return
if (xdmp:get-request-method() eq "POST")
then
  (: validate form and insert record :)
else "display-page"
  (: display the form :)

Best practice would be to have server-side validation of the form contents
as part of the processing.


On Tue, May 29, 2012 at 7:28 AM, Adam Fowler <[email protected]> wrote:

> Add a name attribute to the <input> elements, as browsers tend to use this
> instead of the id attribute when posting information back to a server.
>
> E.g.
>        <input class="input-xlarge" *name="id" *id="id"
>
>               style="font-family:monospace;" type="text"/>
>
> Regards,
>
> Adam.
>
> On 29 May 2012 12:56, Jashank Jeremy <[email protected]> wrote:
>
>> G'day,
>>
>> I'm still relatively new working with XQuery, so if I've done something
>> blatantly and obviously wrong, please don't hurt me!
>>
>> I'm building a webapp in pure XQuery, and using it to teach myself the
>> basics of XQuery.
>>
>> I have a '/cluster-add.xqy', which looks at the value of a hidden value
>> (I need a better way to do it, but that's not critical) and switches
>> between a form and an xdmp:document-insert().  If the form has
>> method="get", nothing happens when I submit -- I just wind up back at an
>> unpopulated '/cluster-add.xqy'.  If I go to
>> '/cluster-add.xqy?aqt=1&name=Test&id=test', then the document-insert()
>> runs.
>>
>> My program, when stripped down to the bare essentials, looks like this.
>>
>> return
>> if (xdmp:get-request-field('aqt'))
>> then
>>  (: inject content into the database :)
>> else
>>  (: generate form :)
>>
>> The form itself looks like this.  I use Twitter Bootstrap to do styling.
>>
>> <form action="/cluster-add.xqy" method="get" class="form-horizontal">
>>  <fieldset style="border: 0px;">
>>    <legend>Add cluster</legend>
>>    <div class="control-group">
>>      <label class="control-label" for="name">Name</label>
>>      <div class="controls">
>>        <input class="input-xlarge" id="name" type="text"/>
>>      </div>
>>    </div>
>>    <div class="control-group">
>>      <label class="control-label" for="id">Identifier</label>
>>      <div class="controls">
>>        <input class="input-xlarge" id="id"
>>               style="font-family:monospace;" type="text"/>
>>      </div>
>>    </div>
>>    <input type="hidden" id="aqt" value="1"/>
>>    <div class="form-actions">
>>      <button type="submit" class="btn btn-primary">Create</button>
>>      <button type="reset" class="btn">Reset</button>
>>    </div>
>>  </fieldset>
>> </form>
>>
>> Any thoughts?
>>
>> Thanks in advance,
>>
>> Jashank
>>
>> --
>> Jashank Jeremy
>> PGP: 0x25A5C309
>>
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://community.marklogic.com/mailman/listinfo/general
>>
>>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://community.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
http://community.marklogic.com/mailman/listinfo/general

Reply via email to