这是我第一次认真涉足javascript / ajax。
概述: 我有一个索引页面列出了多个记录,每个记录在不同的行上。对于每个记录,我有一个链接,弹出一个包含symfony表单的小javascript窗口。一切顺利,除了我无法弄清楚如何传递弹出javascript每个记录的对象Id。这就是我所拥有的:
从行动开始:
public function executeTrackReferrals(sfWebRequest $request){
$userId = $this->getUser()->getId();
$this->pager = new sfDoctrinePager('referral', sfConfig::get('app_pager'));
$this->pager->setQuery(Doctrine_Core::getTable('Referral_submissions')->getUsersSubmissions($userId));
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();}
主要索引页面:
<?php
include_partial('<a bunch of other includes >');
include_partial('referral/rtsIndex', array('pager' => $pager));
?>
_rtsIndex partial:
<table>
<?php foreach ($pager->getResults() as $r => $referral): ?>
<?php
$referralObject = Doctrine_Core::getTable('referral')->getReferralObjectById($referral->getId());
$submissionObject = Doctrine_Core::getTable('referral_submissions')->getObjectByReferralId($referralObject->getId());
?>
<TR VALIGN=TOP>
<td WIDTH=10% ALIGN="center" class="_7">
<P ALIGN=CENTER>
<script type='text/javascript'>
$('.popup_changestatus').click(function(){
// put the row id into the hidden field in the popup
var rowId = $(this).parent().find('span.row_id').html();
$('test').val(rowId);
fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup");
return false;
});
</script>
<a href="#" class="popup_changestatus">
<?php echo utilities::getStatusCode($submissionObject->getCandidateStatus()); ?>
</a>
<span class="row_id" style="display: none">
<?php echo $referral->getId() ?>
</span>
</P>
</td>
</TR>
</table>
上面提到的Javascript弹出窗体代码,包括以下行:
<?php include_partial('referral/changeStatusCodeForm'); ?>
以上行呈现实际的symfony形式:
_changeStatusCodeForm partial:
<?php
$object = new referral_submissionsForm(<this is where I need to pass an ID for each popup form>);
echo $object;
?>
有人能引导我朝着正确的方向前进吗?
如果对实际的javascript代码感兴趣,它是一个非常漂亮的开源弹出窗口: http://www.html-form-guide.com/contact-form/simple-modal-popup-contact-form.html
编辑: 以下是contactform-code.php的内容:
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/gen_validatorv31.js'></script>
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/fg_ajax.js'></script>
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/fg_moveable_popup.js'></script>
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/fg_form_submitter.js'></script>
<div id='fg_formContainer'>
<div id="fg_container_header">
<div id="fg_box_Title">Change Status</div>
<div id="fg_box_Close"><a href="javascript:fg_hideform('fg_formContainer','fg_backgroundpopup');">Close(X)</a></div>
</div>
<div id="fg_form_InnerContainer">
<form id='contactus' action='javascript:fg_submit_form()' method='post' accept-charset='UTF-8'>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'>* required fields</div>
<div id='fg_server_errors' class='error'></div>
<div class='container'>
<?php
// $form = new referral_submissionsForm();
include_partial('referral/changeStatusCodeForm');
?>
</form>
</div>
</div>
答案 0 :(得分:0)
首先,您不应该直接在模型中使用Doctrine_Core
。这里最好的方法是在将查询传递给寻呼机时在2个表上创建leftJoin
。然后,在您的模板中,您只需获取关系(例如$object->getRelation()
)。
关于您的问题,您应该在构建<div id='fg_formContainer'>
时传递ID,因为它是弹出窗口的内容。该部分来自此文件:contactform-code.php
。
告诉我们您在哪里构建此div
,您将拥有通过id
的地方。
修改强>
好吧,我终于明白了你的问题。您的页面上有一个弹出窗口定义,可以在每行的每次单击时调用。并且您想知道如何将行ID传递给全局弹出窗口。
这可以在javascript中完成。而不是:
<a href='javascript:fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup" );'>
<?php echo utilities::getStatusCode($submissionObject->getCandidateStatus()); ?>
</a>
你可以更好地使用:
<a href="#" class="popup_contact">
<?php echo utilities::getStatusCode($submissionObject->getCandidateStatus()); ?>
</a>
<!-- use this hidden span to put the row id, to be able to retrieve it using jQuery -->
<span class="row_id" style="display: none">
<?php echo $referral->getId() ?>
</span>
然后,使用jQuery定义一个动作(例如):
$('.popup_contact').click(function() {
// put the row id into the hidden field in the popup
var rowId = $(this).parent().find('span.row_id').html();
$('#submitted').val(rowId);
fg_popup_form("fg_formContainer", "fg_form_InnerContainer", "fg_backgroundpopup");
return false;
})