CodeIgniter How to use onsubmit event in form_open()

岁酱吖の 提交于 2019-12-25 02:57:08

问题


In HTML, I can call a javascript function like below

 <form type="post" onsubmit ="return test()" >
 </form>

How do I call the same javascript function in

 form_open();

When form gets posted, I want function test to be called. How do I do above in CodeIgniter?

Update

x.html is my HTML page

   <form>
    </form>

    <?php $data = array('submit'=>"test()");
   echo form_open(x,$data);
  echo  form_close();
    ?>

回答1:


In your template file x.html use

<?php $data = array('onsubmit' => "test()"); ?>
<?php echo form_open('email/send', $data); ?>
<?php echo form_submit('mysubmit', 'Submit Post!'); ?>
<?php echo form_close(); ?>

it works correctly




回答2:


add it as array in 2nd param of form_open()

<?= form_open('email/send', array('onsubmit' => 'your js')); ?>

read http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html




回答3:


should try this

  <?php echo form_open($base_url.'pjremove', "style='display:inline' onsubmit='confirm(your message)'"); ?>


来源:https://stackoverflow.com/questions/15448882/codeigniter-how-to-use-onsubmit-event-in-form-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!