0
votes

I'm trying to use Javascript's onclick submit function on the view file of Cakephp site and it doesn't seem to do anything when it's clicked...

Any suggestions?

<?php echo $form->submit('  Preview  ', array('label'=>false,'name'=>'submit','id'=>'print_log')); ?>
<a id="print_log" href="#" onclick="this.form.submit()" name="submit">
<?php echo $html->image("btn_preview.jpg",array("alt" => "Preview")); ?>
</a>
1
I've actually used button function with style background and url with image path and it worked! Below is my answer: <button style="border: medium none; background: url('/img/btn_preview.jpg') no-repeat scroll 0pt 0pt transparent; height: 26px; width: 85px; cursor: pointer;" type="submit"></button> Strange that Cakephp does not allow onclick function to work with form properly when submitting through Javascript. Anyways, job done! - Passionate Engineer
You might as well add this as an answer and possibly also accept @lxa 's answer - icc97

1 Answers

1
votes

<a> is not a form element (while <input> or <button> are), therefore this.form is undefined for it. It has nothing to do with CakePHP.