dops57958 2012-10-16 15:25 采纳率: 0%
浏览 34
已采纳

Yii - 如何提交表单并将用户发送到给定的锚点?

I need to achieve in Yii something like this:

<form action="somescript.php#fragment-id">

Once the form get's submitted, the success message should appear in front of the user eyes. At this time, the message is displaying BUT, the browser goes back to the top.

<?php $form=$this->beginWidget('CActiveForm', array(
                    'id'=>'contact-form',
                    'enableClientValidation'=>true,
                )); ?>

  //form here
  <?php echo CHtml::submitButton('send')); ?>

<?php $this->endWidget(); ?>

I see something here called actionPrefix, but it seems to be coming from another class:

CWidget

http://www.yiiframework.com/doc/api/1.1/CActiveForm

I've tried to add actionPrefix like so:

<?php $form=$this->beginWidget('CActiveForm', array(
                    'id'=>'contact-form',
                    'enableClientValidation'=>true,
                    'actionPrefix'=>'fragment-id'
                )); ?>

No dice.

Please advice

  • 写回答

3条回答 默认 最新

  • dongyi5070 2012-10-16 15:49
    关注

    In the controller/action that receives your form submit, once the form is processed, simply redirect to the URL you want. eg:

    $this->redirect(Yii::app()->request->baseUrl."/myurl#fragment-id");
    

    You can even get real fancy and use this short jQuery scroll to function:

    function goToByScroll(id){
        $('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
    }
    

    Which get's called like so:

    goToByScroll("theIdIWantToGoTo");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?