On 15 Feb, 06:20, freech <[EMAIL PROTECTED]> wrote:
> 1. I handle the check.php file like:
> <?php
> if (!isset($_POST['username'])) echo "please input a username";
> ... if $username already exists, echo "the name you try to register is
> already taken";
I think you could insert in your document a <div> with an
id="errorMessage" (or whatever)
and then change the callback function of $.post so that it puts the
response message in the div.
for example
$.post('check.php',
{
username: $('#username').val(),
password: $('#password').val()
},
function(data){
$('#errorMessage').html(data);
// but you still need some check to see if the form is ok
// what does 'check.php' send back in case the form is
ok?
// I assume nothing, so:
if (data != "") return false;
else return true;
});
now I'm just thinking that maybe doing as I suggested wil not work,
because $.post is an asynchronous request.
you may want to lock the page somehow, and get a synchronous request,
and have the form submit waiting for the response...
not sure (I'm not that expert I fear), so have a look here
http://docs.jquery.com/Ajax/jQuery.ajax#options
:)
> 2. I used <form TARGET="<?php echo "$PHP_SELF"; ?>" to write the
> register form & data insert in same file: register.php, is there any
> way to combine the functions in check.php into register.php, which
> means all of the actions will be executed in 1 file? looks like
> $.post('register.php'), (call itself), are there any good solutions?
actually I don't know how that would work.
but you can try and let us know :)
good luck