0

这是我第一次认真尝试 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 部分:

<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 部分:

<?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>
4

1 回答 1

0

首先,您不应该直接Doctrine_Core在模型中使用。最好的方法是leftJoin在将查询传递给寻呼机时在 2 个表上创建一个。然后,在您的模板中,您只需获取关系(如$object->getRelation())。

关于您的问题,您应该在构建时传递 ID,<div id='fg_formContainer'>因为它是您的弹出窗口的内容。该部分来自此文件: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;
})
于 2012-07-13T07:33:41.897 回答