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