Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I created this before you post your code. Simple form with login and password.</p> <p>XHTML:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;AJAX Form Submission&lt;/title&gt; &lt;link rel="stylesheet" href="css/jquery-ui.css" type="text/css" media="screen"/&gt; &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="my_script.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="dialog-confirm" title="Registration success"&gt; &lt;p&gt;&lt;span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 20px 0;"&gt;&lt;/span&gt;Your account have been created successfully.&lt;/p&gt; &lt;/div&gt; &lt;form method="post" action="#" id="reg_form"&gt; &lt;p&gt;&lt;label for="reg_login"&gt;Login&lt;/label&gt;&lt;/p&gt; &lt;p&gt;&lt;input id="reg_login" type="text"/&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="reg_password"&gt;Password&lt;/label&gt;&lt;/p&gt; &lt;p&gt;&lt;input id="reg_password" type="password" /&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="submit"&gt;&lt;/p&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Javascript:</p> <pre><code>$(document).ready(function() { $( "#dialog-confirm" ).hide(); $('#reg_form').submit(function() { $.post( "check_user.php", { login: $('#reg_login').val(), password: $('#reg_password').val() }, function(data) { if(data == 'ok') { // clear inputs $('#reg_login').val(''); $('#reg_password').val(''); $( "#dialog-confirm" ).dialog({ resizable: false, height:140, modal: true, buttons: { "Register another": function() { $( this ).dialog( "close" ); window.location = "http://www.example.com/register"; }, Cancel: function() { $( this ).dialog( "close" ); window.location = "http://www.example.com/login"; } } }); } else { // alert('error'); $('.error').remove(); $('#reg_form').before('&lt;p class="error"&gt;Invalid login or password&lt;/p&gt;'); } } ); return false; }); }); </code></pre> <p>PHP:</p> <pre><code>&lt;?php $login = isset($_POST['login']) ? trim($_POST['login']) : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; // check login in DB (don't forget to escape...), check password length // [...] $valid = true; // toggle this to see echo $valid ? 'ok' : ''; ?&gt; </code></pre>
    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.
 

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