Sanitizing HTML in submitted form data

strip_tags actually removes the tags from the input, which may not be what you want. To convert a string to a “safe string” with angle brackets, ampersands and quotes converted to the corresponding HTML entities, you can use the escape filter: from django.utils.html import escape message = escape(form.cleaned_data[‘message’])

How do I style the HTML form validation error messages with CSS?

Currently, there is no way to style those little validation tooltips. The only other option, which is what I have chosen to do, is to disable the browser validation all together for now and rely on my own client-side validation scripts. According to this article: http://blog.oldworld.fr/index.php?post/2010/11/17/HTML5-Forms-Validation-in-Firefox-4 “The simplest way to opt out is to add … Read more

Why is the comma URL encoded?

The URI spec, RFC 3986, specifies that URI path components not contain unencoded reserved characters and comma is one of the reserved characters. For sub-delims such as the comma, leaving it unencoded risks the character being treated as separator syntax in the URI scheme. Percent-encoding it guarantees the character will be passed through as data.

is_valid() vs clean() django forms

is_valid() calls clean() on the form automatically. You use is_valid() in your views, and clean() in your form classes. Your clean() function will return self.cleaned_data which if you will notice in the following view is not handled by you as the programmer. form = myforms.SettingsForm(request.POST) if form.is_valid(): name = form.cleaned_data[‘name’] #do stuff You didn’t have … Read more

What is the meaning of onsubmit=”return false”? (JavaScript, jQuery)

This is basically done to handle the form submission via JavaScript. For example – for validation purposes See the below code and see how it can be beneficial: <script language=”JavaScript”> myFunctionName() { if (document.myForm.myText.value == ”) return false; // When it returns false – your form will not submit and will not redirect too else … Read more

What is the correct input type for credit card numbers?

HTML If you’re trying to do this strictly with HTML, I believe the following is going to get you about as close as is currently possible: <label for=”ccn”>Credit Card Number:</label> <input id=”ccn” type=”tel” inputmode=”numeric” pattern=”[0-9\s]{13,19}” autocomplete=”cc-number” maxlength=”19″ placeholder=”xxxx xxxx xxxx xxxx”> inputmode sets the keyboard type (in this case, numeric) pattern enables validation (in this … Read more