开发者

Sending data to modal window, then posting form in original window

I'm using php and jquery. I have a form in php, after filling in the form, I wanna be able to click submit and send the data to a modal window pop up, where the form data is displayed. There will be an additional textbox to fill in, then after clicking another submit, this textbox + the form data will be sub开发者_运维百科mitted to a processing page on the parent window.

So basically, i dunno how to -

1) Pass form data from form to modal window - do i use json stringify and if so how?

2) How to submit from the modal window the previous form data + data in the textbox back to the original form

Thanks


2) How to submit from the modal window the previous form data + data in the textbox back to the original form

After opening new window with window.open(), you can access "parent window" via window.opener. E.g., if you have <form id='foo'/> in parent window, you can access it as $(window.opener).find('#foo') from "modal" window.


1) Pass form data from form to modal window - do i use json stringify and if so how?

What about sending POST to the same window, validating data, reloading the page and if everything is successful in the first form, then showing modal window after reloading the page? Data could be stored in $_SESSION, that way you don't have to worry about passing data between windows. Or, if you really want to pass data to the form of child window, you can do something like this (not tested):

var modalWindow = window.open(
    URL, 
    '_blank', 
    'width=400, height=300, left=100, top=300'
);
modalWindow.load(function(){
    var form = $(this).find('#idOfFormInModalWindow');
    form.find('[name=someField1]').val('someValue1');
    form.find('[name=someField2]').val('someValue2');
    form.find('[name=someField3]').val('someValue3');
});

someValue1, someValue2, someValue3 would be values from $_POST, passed through json_encode().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜