Display validation on same page after submit

Hi folks, i am using this captcha on a website and i am unable to to modify according to what i need. what i need is when i click submit and if the capcha is wrong it should prompt below its field that some error msg. can anyone be kind enough to let me know how can i do that?
in the example. he is calling another page for success and fail msg which i don’t want so i am using php self on form

What exactly is the problem? What have you got so far?

So far its working fine like its suppose to i.e when captcha is correct it echo out success on next pased which is in form action. what i want is when a person submit a form. the page within itself checks and print out error or success. in other words what i want is whatever msg comes out of submit button to be displayed in same page (i dont want the other page)

Is the action of your form set to POST to itself? Its easiest to do this sort of thing if the page your form is on POSTs to itself. Your script then does the processing if the page has been POSTed, eg:

if ("POST" == $_SERVER['REQUEST_METHOD']) {
    // form processing
}

This also makes it easy to refill the form values with the submitted values (so they don’t have to refill them manually).

ok now i m stuck somewhere else. now the page is displaying the msg if captacha isn’t filled. now the msg which i show based on session. it stays there and is confusing for someone who is re filling the form.how can i hide the error msgs after a person start filling again or do refresh?

How are you showing the messages? Showing us your code will help

You’ll need some Javascript (suggest jQuery) to hide the messages when the user puts the values in.

that helped. Thank you!
But i was seeing into code. As it set value of session[‘abc’] and then reusing it in if else statement. how can we use session[‘abc’] without assigning it to variable. i was wondering how could it work as it was working