Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way for form validation in PHP and JS
    text
    copied!<p>I was wondering what actually the best way for a solid form validation is.</p> <p>JavaScript does a quite good jon, but it is not a base for a solid validation, because it can be manipulated or even disabled.</p> <p>If you check the data with PHP and re-populate a form when an error occurrs, there are several problems with a post form. </p> <ul> <li>If the form is displayed without redirecting, then F5 will show a confirm box if the user wants to re-send the data, this is not really beautiful.</li> <li>If the user gets redirected to the form again, the data must be submitted by <code>GET</code> or <code>POST</code>. With <code>POST</code>, there is again the F5-Problem as mentioned above. With <code>GET</code>, a problem exists when transferring values with a <code>&amp;</code> inside (PHP guesses another parameter after the sign)</li> <li>A third way would be to store the data in a database, e.g. SUBMITTRIALS or something like that. But then you'd actually have to clear the data after redirecting.</li> </ul> <p>Another problem comes along with re-populating of the form itself: A code like this:</p> <pre><code>echo "&lt;input type='text' value='".$val."' /&gt;"; </code></pre> <p>is quite a problem if the variable <code>$val</code> contains a value containing apostrophes, this generates invalid HTML.</p> <p>As you can see, there are quite much possibilities of failure in a form validation scenario. What would be the most reliable way to handle form-validation as described at top?</p>
 

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