Calling a Site Entry from a form

Updates
16th November, 2009: or use action=post.

In Content Server Explorer, you can create a JSP that is addressable through a Site Entry. For example, create a Content Server Element named my/site/FormResponse and a Site Entry whose RootElement is my/site/FormResponse.jsp - and you can reach that element with a URL such as: http://SERVER/servlet/ContentServer?pagename=my/site/FormResponse. Content Server is the controller (/servlet/ContentServer) that invokes other elements based on the GET arguments sent to it :?pagename=my/site/FormResponse for example.

That's good, but you cannot use that URL directly in a form's action attribute, such as below.

<FORM ACTION="http://SERVER/servlet/ContentServer?pagename=my/site/FormResponse">
<INPUT TYPE="Submit" VALUE="Submit"/>
</FORM>

That's because in a form's action attribute, any GET style arguments at the end of the URL are ignored. So the URL invoked from the FORM above would be http://SERVER/servlet/ContentServer. The fix is simple enough. Put the pagename argument in a hidden field, such as below.

<FORM ACTION="http://SERVER/servlet/ContentServer">
<INPUT TYPE="Submit" VALUE="Submit"/>
<INPUT TYPE="Hidden" NAME="pagename" VALUE="my/site/FormResponse"/>
</FORM>

Or (much simpler!) just explicitly specify action as POST.

<FORM ACTION="http://SERVER/servlet/ContentServer?pagename=my/site/FormResponse" action="POST">
<INPUT TYPE="Submit" VALUE="Submit"/>
</FORM>

Popular Posts