Hi Andrea,

Thank you, you got my flow right and the explanation is very clear, so
I should put all the actions rely on those data into the callback
function of $.post.

for e.g.
     $.post('check.php',
       {username: $('#username').val(),password: $
('#password').val()},
       function(data){
             if (data == 'true') return true;
                    else return false;
       });


I will try to figure it. I have 2 questions on following:

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";

so, back to the callback function,
     $.post('check.php',
       {username: $('#username').val(),password: $
('#password').val()},
       function(data){
             if (data == 'true') return true;
                    else return false;
       });
the "data" will be something looks like: "please input a username",
"the name you try to register is already taken", as the check.php file
outputs.  instead of { data == 'ture' }.

I feel to get "data" from check.php to decide return ture or false is
not workable if I design the check.php file like above.
Any good ideas?


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?






On Feb 15, 6:00 am, andrea varnier <[EMAIL PROTECTED]> wrote:
> On 14 Feb, 15:57, freech <[EMAIL PROTECTED]> wrote:
>
> >       //I have problem on here:
> >       if ( !$(".sdComt").response )  { return false; }  else { return
> > true; }
>
> ok, if I got it right, you're using a $.post call to check if the
> user's input is correct or somehow acceptable, and then you append to
> the form an hidden input to be checked on submit.
> ok, assuming that check.php returns the string 'true' or 'false', one
> way of doing that is adding a listener for the submit action of your
> form.
>
> $('#sdComt').submit(function(){
>      //code here
>
> });
>
> inside this event handler you will put your ajax call.
>
> $('#sdComt').submit(function(){
>      $.post('check.php', {.....
>
> });
>
> in order to decide whether the form is to be passed or not, you will
> have to wait for the response.
> so all the actions that rely on those data, have to be put in the
> callback function of $.post
>
> $('#sdComt').submit(function(){
>      $.post('check.php',
>        {username: $('#username').val(),password: $
> ('#password').val()},
>        function(data){
>              if (data == 'true') return true;
>                     else return false;
>        });
>
> });
>
> hope this helps... but I'm not sure I got the flow right :)

Reply via email to