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 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决