Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
I posted a related issue some time ago (viewtopic.php?f=4&t=9065&p=18708&hilit=Contact+Form#p18708).

I assume that CouchCMS provides some basic PHP server-side validation / sanitization of forms. (Correct me if I am wrong and it only provides front-end validation). For security reasons, I would like to avoid having to write my own data validation functions on the server.

I have a basic contact form that I am validating on the front-end with jQuery Validate (http://jqueryvalidation.org/) as I find this plugin more intuitive to use (works without problems) , but would like to use CouchCMS for back-end validation of the inputted data of the form. Now, I don't know if this is possible, because in the case of using jQuery Validate, I am not sure if I can use the CouchCMS form validation tags (or can I ?!?).

My form looks like this:

<!-- contact form -->
<form id="contactForm" class="contact-form" method="post" action="">

<div class="row">

<div class="l-contact-left">

<label for="firstname">First Name</label>
<input type="text" id="firstname" name="firstname"><br>

</div>

<div class="l-contact-right">

<label for="lastname">Last Name</label>
<input type="text" id="lastname" name="lastname"><br>

</div>

</div>


<div class="row">

<div class="l-contact-left">

<label for="email">E-Mail</label>
<input type="email" id="email" name="email"><br>

</div>

<div class="l-contact-right">

<label for="phone">Phone</label>
<input type="number" id="phone" name="phone" min="1"><br>

</div>

</div>


<div class="row">

<div class="l-contact-left">

<label for="company">Company</label>
<input type="text" id="company" name="company"><br>

</div>

<div class="l-contact-right"></div>

</div>

<label for="message">Message</label>
<textarea rows="8" id="message" name="message" placeholder="Your message"></textarea><br><br>

<input class="btn btn-contact" type="submit" value="Submit">

</form><!-- /contact form -->


Furthermore, as the server I am working on does not support the PHP mail() function, I will have to use a library like PHPMailer, which another user already laid out (viewtopic.php?f=4&t=8675&p=16802&hilit=Contact+Form+PHPMailer#p16802).

Would appreciate your advise if this is possible as intended.
Hi JD,

I tried to clear your doubts in my answer to the post you mentioned (viewtopic.php?p=18698#p18698).
Will try again :)

See, *all* the validations that Couch provides are *server-side*.
For example, in the following, the check for the input not being empty and having a valid email is all done at the server when the form is submitted.
<cms:input type="email" id="email" name="email" required='1' validator='email' />

If you want to, you can add client-side validation (e.g. using JQuery etc.) if you like.
Do whatever you'd normally do with ordinary forms and it should work.

Please try out and let me know if something doesn't work.
Thanks for your answer.

Ok, got it now. I overlooked that the couch tags are compiled into "normal" HTML/PHP when you browse the site,
hence front-side validation can be applied as normal.

Just for clarification:

- Can I use any validator from the editable regions (http://www.couchcms.com/docs/tags-refer ... table.html)?
- Is there a way to customize the error message depending on the validator applied ? (e.g. when you apply multiple validators)
couch tags are compiled into "normal" HTML/PHP when you browse the site...
That is indeed the crux of the matter. I should have mentioned that myself in the first place :)

Can I use any validator from the editable regions (http://www.couchcms.com/docs/tags-refer ... table.html)?
Oh yes! Every single of them.

Is there a way to customize the error message depending on the validator applied ? (e.g. when you apply multiple validators)
The 'validator_msg' parameter does that. Please find details of it on the doc page mentioned before (it has examples with multiple validators too).

Hope it helps.
4 posts Page 1 of 1