Php edit page launching in shadowbox, need to refresh parent page onclick for save button
I'm wondering if the best way to tackle this is in PHP or using jQuery? Not sure how best to tie together refreshing the parent page's data when the user hits save in the edit window and submits changes. The code to launch the window is below:
<a href=\"/" . $Controller->Organization . "/community/edit_entry/?entry_id=" . $comEntry->getID() . "\" class=\"lightview\" title=\":: :: width:600, height:380, topclose:t开发者_开发技巧rue\" rel=\"iframe\">edit</a>
And in the edit page here is the code for the save button:
<fieldset class="submit actions">
<input id="signup" type="submit" name="signup" class="submitbtn" value="Save" />
<input type="button" class="secondary" name="butClose" id="butClose" value="Close" onclick="window.parent.Lightview.hide();" />
</fieldset>
You can utilize jQuery and setup an onclick()
event handler to refresh the page on the click of the save button. In addition, you could apply form validation if needed, and only refresh the page if all requirements are met. Without knowing specifically what your project entails, you may also be able to just do everything via AJAX and not reload the page at all.
As you may see in your code example (the "edit" window), the shadowbox snippet uses window.parent
for accessing the parents window element to close the box.
You have to write your own JavaScript and add an id (something like butSubmit
) to the submit button. Something like this:
$('butSubmit').onClick({
// Reference to the parent window
var parentWindow = window.parent;
// Accessing the parent windows jQuery object
// and find the element with id #myTargetElement
var targetElement = parentWindow.$('#myTargetElement');
// Current window elements (with id #myInputField) value
var content = $('#myInputField').val();
targetElement.text(content); // May use .html() or .val()
parentWindow.Lightview.hide(); // Close the box
});
Ah yeah, I assume you have loaded jQuery on both (!) windows.
However, this does not save your content. You shoud use the jQuery.ajax() method for solving this.
精彩评论