Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML form with no action (+ CSP rule no inline javascript)

In the past when I've wanted to disable the default action of a form, I've done

<form action="javascript:void(0);">

We now employ a CSP (Content Security Policy) to disallow inline JavaScript. How can we disable the default form action without the inline js?

like image 981
KayakinKoder Avatar asked Dec 08 '25 09:12

KayakinKoder


2 Answers

use jquery

<script>
    $(document).ready(function () {

        $("#form").submit(function (e) {

            //stop submitting the form 
            e.preventDefault();
            return true;

        });
    });
</script>
like image 125
Amospikins Avatar answered Dec 09 '25 23:12

Amospikins


You can disallow all form actions from the HTML document by setting form-action 'none'.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/form-action

like image 29
Null Avatar answered Dec 09 '25 22:12

Null