【问题标题】:How can i show an alert in cakephp with script如何使用脚本在 cakephp 中显示警报
【发布时间】:2014-06-04 19:25:12
【问题描述】:

您好,我想知道如何使用脚本在 cakephp 中显示警报...我有这个表格

<div class="soyaproductorcompras form">
 <h3>Registro de Compra de Grano </h3>
<?php echo $this->Form->create('SoyaProductorCompra');?>
    <fieldset>

        <?php 

        echo $this->Form->input('soya_proveedor_id', array( 'options' => $soyaproveedores,'empty' => '--Porfavor Seleccione Proveedor--','label' => 'Por Favor Seleccione a algun Proveedor de la lista' ));

        echo $this->Form->input('producto', array(
            'options' => array( 
                'GRANO DE SOYA' => 'Grano de Soya',
                'GRANO DE GIRASOL' => 'Grano de Girasol'
                ), 'label'=>'Tipo de Grano  '
        ));

        echo $this->Form->input('toneladas', array('label' => 'Cantidad en tonelada(s) métrica(s) del producto  (TM)','style'=>'width:500px; height:30px;','default'=>0));

        echo $this->Form->input('preciodolar', array(
            'label' => 'Precio en Dolares Americanos por tonelada métrica (TM / $us)',
            'style'=>'width:500px; height:30px;',
            'default'=>0));

            echo $this->Form->input('total', array('label' => 'Total en Dolares Americanos ($us)','style'=>'width:500px; height:30px;','default'=>0));

        echo $this->Form->input('fecharegistro', array('dateFormat' => 'DMY', 'minYear' => date('Y')-3,
                                             'maxYear' => date('Y') + 1, 'label' => '<strong>Periodo al que corresponde la declaración jurada</strong>','empty'=>false, 'type'=>'date'));

        echo $this->Form->submit('Agregar Existencia', array('class' => 'form-submit',  'title' => 'Presione aqui para agregar datos')); 
?>
    </fieldset>
<?php echo $this->Form->end(); ?>
</div>

所以我不知道如何以及在何处放置脚本以及如何调用它...此表单为 DB 发送数据..该部分运行良好!...但我的客户希望看到一个带有类似这样的消息“您确定要保存此表单吗??”他点击是或否请帮忙!!!

【问题讨论】:

  • 所以写一些javascript来拦截表单提交并显示一个确认框。这不是 CakePHP 特有的,可以相对容易地完成。 stackoverflow.com/questions/6515502/…
  • 这里有类似的问题---stackoverflow.com/questions/5455092/…
  • 谢谢@cillosis 我看到了这个问题,我开始搜索 html 而不是 cakephp 解决方案,现在我的代码可以工作了!..我将为想要相同的人提供 tje 解决方案...谢谢又来了!
  • @Tasos 谢谢我看到了解决方案并帮助了我这么多!!!谢谢!..我很高兴成为starkoverflow这个家庭的一员!!...谢谢!!

标签: javascript php cakephp-2.0 cakephp-2.3


【解决方案1】:

好吧,我的问题在here的帮助下得到了解决……所以我的代码稍微改变了一点……你只是在我的观点开始时添加了我的脚本……

<script>
function show_alert()
{
   if (confirm("¿Esta seguro guardar el formulario?")) { return true; } 
   return false;
}
</script>

在我的表单中,我像这样更改我的提交,

echo $this->Form->submit('Agregar Existencia', array('class' => 'form-submit',  'title' => 'Presione aqui para agregar datos', 'onclick' => 'return show_alert();')); 

请注意,该函数有这个'return'并以';'结尾,如果你不放这些东西代码不起作用......我希望我的解决方案能有所帮助!!

【讨论】:

    【解决方案2】:
    Create js file and put it in webroot/js folder
    just link it with your view as follows
    echo $this->Html->script('your_file_name'); 
    function desired_fun_name()
    {
    alert();
    }
    and write your desired function and call it on onclick
    

    如下: echo $this->Form->submit('Agregar Existencia', array('class' => 'form-submit', 'title' => 'Presione aqui para agregar datos', 'onclick' => 'desired_fun_name() '));

    【讨论】:

      猜你喜欢
      • 2011-02-05
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 2019-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多