0

我的应用程序有带有添加操作的联系人控制器,可以将联系人消息发布到数据库表评论。它的验证工作正常。现在,我想将添加视图(联系人表单)用作要在应用程序的所有页面中呈现的全局表单。

我知道,要做到这一点,我必须使一个元素包含表单(或添加视图),如下所示:

元素/contact.ctp

<div class="panel">
    <h4><?php echo __('contact'); ?></h4>
<?php echo $form->create('Contact',array('action'=>'index', 'class' => ''));?>
<?php echo $form->input('name', array('size' => 45, 'class' => 'input-text', 'label' => array( 'text' => __('name',true).'<sup>*</sup>'), 'error' => array('class' => 'error', 'wrap' => 'small')));?>
<?php echo $form->input('email', array('size' => 45, 'class' => 'input-text', 'label' => array('text' => __('email',true).'<sup>*</sup>'), 'error' => array('class' => 'error', 'wrap' => 'small')));?>
<?php echo $form->input('subject', array('type' => 'select', 'options' => array(null => __('choose subject',true), 'g' => __('general', true), 'r' => __('report', true)), 'class' => 'input-text', 'label' => array('text' => __('subject', true).'<sup>*</sup>'),'error' => array('class' => 'error', 'wrap' => 'small'))); ?>
<?php echo $form->input('content', array('class' => 'input-text', 'style' => 'height: 140px', 'title' => __('message', true),  'label' => array('text' => __('message',true).'<sup>*</sup>'), 'error' => array('class' => 'error', 'wrap' => 'small')));?>
<?php //echo $fck->load('Contact.message','Mini'); ?>
<span>    
<?php
App::import('Vendor','FoxCaptcha', array('file' => 'Fox_captcha.php'));
       $cap = new Fox_captcha(120,30,5);

                       $cap->image_dir = $html->url('/').'img/';

      $cap->lines_amount = 13;
       $cap->en_reload = $html->image('reload.png', array('alt' => __('reload', true), 'title' => __('reload the captcha', true), 'id' => 'frel', 'style' => 'vertical-align:middle'));

?>
</span>
<div>    
<span class="display:inline"><?php echo $cap->make_it('HTML');?></span>
<?php echo $form->input('vcode', array('size' => 45, 'class' => 'small input-text', 'label' => array('text' => __('captcha', true).'<sup>*</sup>'), 'error' => array('class' => 'error', 'wrap' => 'small')));?>
</div>



<?php echo $form->submit(__('send',true), array('class' => 'nice medium radius white button'));?>

<?php echo $form->end();?>
<div class="alert-box warning"><?php echo __('fields label with * are required');?></div>
</div>

问题是:当我从任何页面(例如帖子/视图/22)使用此表单时,它会提交给联系人/添加。我希望在提交帖子/视图/22 后触发任何验证消息。

4

1 回答 1

0

There is no solution for this requirement without Ajax and JSON. It includes submitting the form with Ajax to the contacts controller index action with event handler component activated and then check isAjax then render JSON output retrieved by the post's view and then populates the results.

于 2012-08-19T15:59:26.500 回答