wysocki wrote: If I use an html <textarea> then it's not included in the k_success variable
Can't agree here. The thing is, to be included in k_success area, Couch creates internally frm_* variables for each of its cms:input. So, we can also create these variables externally in code for bare-bone html5 inputs. And name them the usual way (as we like).
- Code: Select all
<cms:set frm_book = "<cms:gpc 'book' />" scope="parent" />
The piece above would take the values from the submitted form and does the trick. Probably you forgot to include it in k_error. I am sure

I have used creation of
frm_comment in the previous answer.
Now, to show submitted values in your inputs "as is" we must remove couch inputs and have only html5 left. k_success will still have both variables, because we take care of it. Validation is now on the shoulders of browser and html5 code, instead of server-side validation. Below is a full working sample of such a form.
- Code: Select all
<cms:form name='form2' method='post' >
<cms:if k_success >
<cms:set frm_comment = "<cms:gpc 'comment' />" scope='parent' />
<cms:set frm_book = "<cms:gpc 'book' />" scope='parent' />
<cms:dump />
<p>Success</p>
<cms:else_if k_error />
<cms:set frm_comment = "<cms:gpc 'comment' />" scope='parent' />
<cms:set frm_book = "<cms:gpc 'book' />" scope='parent' />
<cms:show k_error />
<cms:dump />
<p>Error!</p>
</cms:if>
Book:<input type="text" name="book" pattern=".{20,}" title="Minimum length - 20" required='1' value="<cms:show frm_book />">
Desc:<textarea name="comment" ><cms:show frm_comment /></textarea>
<cms:input type='submit' name='submit' value='submit' />
</cms:form>
I have used title field for validation message. If it doesn't suit you completely then to customize validation error message there is another solution with a bit of JS. Instead of title place both commands below inside the target input and it will completely replace default browser message.
oninvalid="this.setCustomValidity('Put here custom message')"
oninput="setCustomValidity('')"
Hope this answers your request.
And, please, make sure to sanitize user-submitted values before storing in database or using somewhere.
cms:html_encode would be enough.