0

Hi i want to know how can i show an alert in cakephp with script...i have this form

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

So i don't know how and where to put the script and how to call it...this form sends data for DB..that part is working good!...but my client want to see a miniscreen with a message like this "Are you sure you want to save this form??" and he click yes or no please help!!!

MickyScion
  • 526
  • 2
  • 14
  • So write some javascript to intercept the form submission and show a confirmation box. This is not specific to CakePHP and can be done relatively easily. http://stackoverflow.com/questions/6515502/javascript-form-submit-confirm-or-cancel-submission-dialog-box – Jeremy Harris May 28 '14 at 01:34
  • Theres a similar question here --- http://stackoverflow.com/questions/5455092/cakephp-javascript-confirm-dialog-form-submission-cancel-not-working – Tasos May 28 '14 at 01:38
  • thanks @cillosis i saw that question and i began to search for html and no for cakephp solutions and now my code works!..i will put tje solution for someone who want the same...thanks again! – MickyScion May 28 '14 at 02:35
  • @Tasos thanks i saw the solution and help me so much!!! thanks!!.. i'm happy to be part of this family that starkoverflow is!!...thanks!! – MickyScion May 28 '14 at 02:36

2 Answers2

0

well my problem was solved with a lot of help from here...so my code change a little bit...y had only add my script at beggining of my view...

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

And in my form i change my submit like this,

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

Note that the function have this 'return' and ends in ';', if you doesn't put those things the code doesn't work... i hope my solution can helps!!

MickyScion
  • 526
  • 2
  • 14
0
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

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

Swapnil Deo
  • 241
  • 1
  • 3
  • 16