目的:在editview中一個儲存按鈕,儲存兩個模組(兩張表)
解決方案:
1.在主表模組的editview.php檔案最後寫
require_once('modules/bw_Consignments/editpanels/editview.php'); //執行子表模組的editview.php檔案
2.在子表模組中建立editpanels檔案夾
將editview.php editview.html Forms.php 檔案複製到此檔案夾下
3.修改editpanels/EditView.php檔案
(1) require_once('modules/bw_Consignments/language/zh_cn.lang.php');//在檔案頭部寫此句,用於引入$mod_strings[]數組
4.editpanels/EditView.html 可根據需求調整模板
(1)去除儲存 取消按鈕 刪除以下代碼
<input type="submit" name="button" value=" {APP.LBL_SAVE_BUTTON_LABEL} "
class="button" tabindex="5"
onclick="this.form.action.value='Save'; return check_form('EditView');"
title="{APP.LBL_SAVE_BUTTON_TITLE}" accesskey="{APP.LBL_SAVE_BUTTON_KEY}"/>
<input type="submit" name="button" value=" {APP.LBL_CANCEL_BUTTON_LABEL} "
class="button" tabindex="6"
onclick="this.form.module.value='{RETURN_MODULE}'; this.form.action.value='{RETURN_ACTION}'; this.form.record.value='{RETURN_ID}';"
title="{APP.LBL_CANCEL_BUTTON_TITLE}"
accesskey="{APP.LBL_CANCEL_BUTTON_KEY}"/>
<td align="right" nowrap><span class="required">{APP.LBL_REQUIRED_SYMBOL}</span> {APP.NTC_REQUIRED}</td>
< td align="right">{ADMIN_EDIT}</td>
(2)去除<form name="EditView" method="post" action="index.php"> </form> 因為表單這個表單不需要了
(3)去除下面代碼
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<input type="hidden" name="module" value="bw_Consignments" />
<input type="hidden" name="record" value="{ID}" />
<input type="hidden" name="action" value="" />
<input type="hidden" name="return_module" value="{RETURN_MODULE}" />
<input type="hidden" name="return_id" value="{RETURN_ID}" />
<input type="hidden" name="return_action" value="{RETURN_ACTION}" />
</tr>
</table>
因為這些是控製表單提交的,表單已經不需要,所以這些也不用了,而且這些與主表模組衝突
5.修改editpanels/Forms.php 檔案
function get_new_record_form 方法名修改為 get_new_record_form1
function get_validate_record_js 方法名修改為 get_validate_record_js1
原因: 因為兩個模組同一頁時,兩個模組均調用了此方法,為了防止重名
6.提交儲存
原理:將兩個模組合成為一個表單一同提交,子表模組仍然由子模組執行儲存.
主表模組的save.php
$return_id = $sugarbean->id; \\此句下面寫
$temp_id=$return_id;//因為$return_id已為子表模組儲存的id 所以用$temp_id
require_once('modules/bw_Consignments/Save.php');//執行子表模組Save.php
//handleRedirect($return_id,'bw_Msg_MT3101s');//原來的,不用了
handleRedirect($temp_id,'bw_Msg_MT3101s');//頁面跳轉
注意: 子表儲存後跳轉應去掉
SaveFormBase.php
//if ($redirect) {
// handleRedirect($return_id,"bw_Consignments" );
//} else {
// return $focus;
//}