Search code examples
javascriptwordpresscontact-form-7

How i can add onsubmit attribute to <form> in contact form 7 and onclick attribute to the submit button in contact form 7


This is my HTML code:

<form id="form" onsubmit="return false;">
<input  type="text" id="userInput" />
<input type="email" id="emailId" />
<input type ="number" id="phoneNumber" />
<input  type="submit" onclick="userdetails();" />
</form>

How i can implement this in contact form 7 of my wordpress website. Also i have multiple forms on same page so please help how i can target a specific form with the above mentioned attributes..???


Solution

  • Here is how you can achieve it :

    <form id="form1">
            <input  type="text" id="userInput">
            <input type="email" id="emailId" />
            <input type ="number" id="phoneNumber" />
            <input  type="button" onclick="userdetails();" value="Details"/>
    </form>
    <form id="form2">
            <input  type="button" onclick="form1.submit()" value="Send" />
    </form>
    

    Explanation :

    I have replace type="submit" by type=button so that it doesn't submit the form. If you need to submit a form you can proceed this way onclick="form_id.submit()".