Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango / Jquery Form Submission
    primarykey
    data
    text
    <p>Im trying to create a simple input box with form validation, but im not 100% sure how issue a post to a URL if successful. Im not 100% sure if I need to issue the post just within the jquery script or if I also need to amend anything within the views.py file...</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Demo&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script src="{{ STATIC_URL }}js/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(function(){ $("#btn-search").click(function(){ $(".error").hide(); var hasError = false; var searchReg = /^[a-zA-Z0-9-]+$/; var searchVal = $("#search-text").val(); if(searchVal == '') { $("#search-text").after('&lt;span class="error"&gt;Please enter a search term.&lt;/span&gt;'); hasError = true; } else if(!searchReg.test(searchVal)) { $("#search-text").after('&lt;span class="error"&gt;Enter valid text.&lt;/span&gt;'); hasError = true; } if(hasError == true) {return false;} else { $("#search-text").after('&lt;span class="error"&gt;Search term accepted.&lt;/span&gt;'); return false; } }); }); &lt;/script&gt; &lt;form method="post" name="form1" action="/whatmask_output/"&gt; {% csrf_token %} &lt;fieldset&gt; &lt;div&gt;&lt;label&gt;Search:&lt;/label&gt;&lt;input type="text" name="search-text" id="search-text" value="" size="32" /&gt;&lt;/div&gt; &lt;div&gt;&lt;label&gt;&lt;/label&gt;&lt;input type="submit" value="Submit" id="btn-search" /&gt;&lt;/div&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Any ideas ??</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload