开发者

Can a form be submitted from a jQuery Colorbox to SELF so that it 'refreshes' in same Colorbox window?

开发者 https://www.devze.com 2023-03-05 21:39 出处:网络
I have a form that is shown inside a Colorbox. When users click submit there is some validation done (checking if an entered field already exists in my database) if it does a messa开发者_JAVA技巧ge is

I have a form that is shown inside a Colorbox. When users click submit there is some validation done (checking if an entered field already exists in my database) if it does a messa开发者_JAVA技巧ge is shown and user is prompted to enter a new value. However when this happens the form is not shown the second time inside the Colorbox window, instead it appears on a blank page.

the form is posted to PHP_SELF, how can i change this to show in PHP_SELF (in the current Colorbox)?

cheers


I know this is aside from what you are asking, but

What if you used jquery's submit() and post() instead of PHP_SELF to pass form data to an external php class and handle displaying the return data? If the data is acceptable, you can call $.colorbox.close() manually. If data is unacceptable you can display a message to the user describing the problem.

$('myform').submit(function(){
    //validate the data with javascript
    //send the data to your function with post
    $.post('http://url/to/your/function',{a:first_input,b:second_input},
        function(return_data){
        if(return_data == 'success'){
           $.colorbox.close();
        }else{
           //display your error message here
        }
        ,html
     );
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号