1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHP2でフォーム送信前にJavaScript処理を走らせる方法

1
Posted at

方法

フォームヘルパーのcreateでフォームを生成時に、onsubmitにJS関数を渡しておけばOK。

echo $this->Form->create('Post', array(
	'onsubmit' => 'doSomething()'
));
function doSomething() {
  //do something
}

例)確認メッセージを出したいとき

以下のようにすれば送信前に確認メッセージを出してくれる。

echo $this->Form->create('Post', array(
	'onsubmit' => 'return confirm('本当に送信しますか?')'
));
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?