# Prevent form submit via javascript

**URL:** <https://forums.knack.com/t/prevent-form-submit-via-javascript/10138>\
**Category:** Get Answers\
**Created:** [September 6, 2016, 4:20am UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138 "2016-09-06T04:20:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markus91352](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Markus91352](https://forums.knack.com/u/Markus91352)\
**Post date:** [September 6, 2016, 4:20am UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138/1 "2016-09-06T04:20:52Z")

</div>

I have a two fields where the user is required to fill only one of them, while the other can be blank. He can also fill both, doesn't matter.

This can not be done with Knack itself (or I don't know how) so I have to resort to a simple custom javascript validation. If both fields are empty, I show an error message and stop the form submitting. And here is my problem. How can I prevent Knack from submitting the form manually? If I listen to the submit event and do a 'return false', it doesn't work. Since I can not see an action url in the form element, I am thinking Knack has it's own form submit logic. How can I capture that and stop it from submitting the form?

Thank you!

---

<div class="post-metadata">

**Author:** ![CarolPinil06400](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@CarolPinil06400](https://forums.knack.com/u/CarolPinil06400)\
**Post date:** [January 11, 2018, 4:20pm UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138/2 "2018-01-11T16:20:12Z")

</div>

```
Hola, estoy interesado en ingresar la documentación pero no puedo iniciar sesión para ver, habrá una forma de obtener la documentación desde otro lado o por favor díganme cuál fue la solución que encontró
```

---

<div class="post-metadata">

**Author:** ![CarolPinil06400](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@CarolPinil06400](https://forums.knack.com/u/CarolPinil06400)\
**Post date:** [January 11, 2018, 4:19pm UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138/3 "2018-01-11T16:19:18Z")

</div>

---------------Detectar idiomaAfricaansAlbanésAlemánAmáricoÁrabeArmenioAzerbaiyanoBengalíBielorrusoBirmanoBosnioBúlgaroCanarésCatalánCebuanoChecoChino (Simplificado)Chino (Tradicional)CingalésCoreanoCorsoCriollo haitianoCroataDanésEslovacoEslovenoEnglishesperantoEstonioEuskeraFinésFrancésFrisón occidentalGaélico escocésGalésGallegoGeorgianoGriegoGuyaratíHausaHawaianoHebreohindiHmongHúngaroIgboIndonesioInglésIrlandésIslandésItalianoJaponésJavanésJemerKazajoKirguísKurdoLaoLatínDejar enLituanoLuxemburguésMacedonioMalayalamMalayoMalgacheMaltésMaoríMaratímongolNeerlandésNepalíNoruegoNyanjaPanyabíPastúnPersaPolacoPortuguésRumanoRusoSamoanoSerbioSesotho meridionalShonaSindhiSomalíSuajiliSuecoSundanésTagaloTailandesaTamilTayikoTeluguTurcoUcranianoUrduUzbekoVietnamitaXhosaYidisYorubaZulúEnglish

&nbsp;

&nbsp;

```
Hello, I am interested in entering the documentation but I can not log in to see, there will be a way to get the documentation from another side or please tell me what was the solution you found
```

---

<div class="post-metadata">

**Author:** ![CarolPinil06400](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@CarolPinil06400](https://forums.knack.com/u/CarolPinil06400)\
**Post date:** [January 11, 2018, 4:17pm UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138/4 "2018-01-11T16:17:03Z")

</div>

* * *

Detectar idioma  
Afrikáans  
Albanés  
Alemán  
Amárico  
Árabe  
Armenio  
Azerbaiyano  
Bengalí  
Bielorruso  
Birmano  
Bosnio  
Búlgaro  
Canarés  
Catalán  
Cebuano  
Checo  
Chino (Simplificado)  
Chino (Tradicional)  
Cingalés  
Coreano  
Corso  
Criollo haitiano  
Croata  
Danés  
Eslovaco  
Esloveno  
Español  
Esperanto  
Estonio  
Euskera  
Finés  
Francés  
Frisón occidental  
Gaélico escocés  
Galés  
Gallego  
Georgiano  
Griego  
Guyaratí  
Hausa  
Hawaiano  
Hebreo  
Hindi  
Hmong  
Húngaro  
Igbo  
Indonesio  
Inglés  
Irlandés  
Islandés  
Italiano  
Japonés  
Javanés  
Jemer  
Kazajo  
Kirguís  
Kurdo  
Lao  
Latín  
Letón  
Lituano  
Luxemburgués  
Macedonio  
Malayalam  
Malayo  
Malgache  
Maltés  
Maorí  
Maratí  
Mongol  
Neerlandés  
Nepalí  
Noruego  
Nyanja  
Panyabí  
Pastún  
Persa  
Polaco  
Portugués  
Rumano  
Ruso  
Samoano  
Serbio  
Sesotho meridional  
Shona  
Sindhi  
Somalí  
Suajili  
Sueco  
Sundanés  
Tagalo  
Tailandés  
Tamil  
Tayiko  
Telugu  
Turco  
Ucraniano  
Urdu  
Uzbeko  
Vietnamita  
Xhosa  
Yidis  
Yoruba  
Zulú

Español

&nbsp;

&nbsp;

```
Hola, estoy interesado en ingresar la documentación pero no puedo iniciar sesión para ver, habrá una forma de obtener la documentación desde otro lado o por favor díganme cuál fue la solución que encontró
```

---

<div class="post-metadata">

**Author:** ![Markus91352](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Markus91352](https://forums.knack.com/u/Markus91352)\
**Post date:** [September 9, 2016, 8:15am UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138/5 "2016-09-09T08:15:28Z")

</div>

Thank you Brad, I don't know how I missed that, I was searching around a lot for custom validation, since I thought this isn't a too exotic request. Still didn't find that :/

In my tries I was listening to the form submit event. Apparently Knack is listening on the click event for the submit button. That's probably why my 'return false' didn't do anything, since it had no effect on the click event.

It is working now with the code provided in the example. I am very happy, thank you very much!!

---

<div class="post-metadata">

**Author:** ![BradStevens](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/bradstevens/32/140_2.png) [@BradStevens](https://forums.knack.com/u/BradStevens)\
**Post date:** [September 8, 2016, 8:46pm UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138/6 "2016-09-08T20:46:58Z")

</div>

Markus - check out the documentation for javascript code examples and this custom validation snippet:&nbsp;[http://helpdesk.knackhq.com/support/solutions/articles/5000447560-javascript-code-examples#jqcustomvalidate](http://helpdesk.knackhq.com/support/solutions/articles/5000447560-javascript-code-examples#jqcustomvalidate)

---

<div class="post-metadata">

**Author:** ![Markus91352](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Markus91352](https://forums.knack.com/u/Markus91352)\
**Post date:** [September 7, 2016, 8:37am UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138/7 "2016-09-07T08:37:41Z")

</div>

Thank you very much, this is close enough and should work just fine, thanks!

Coming back to the original question though, is it possible to intercept the knack form submission? For example validating a name field does not work this way, because inside knack, the name is one field and I can not select first and last name separately. We want to send the data to zapier and to another app which chokes on missing first or last names since they are required there. Knack however does accept only first name or only last name. Do you have any idea about that?

---

<div class="post-metadata">

**Author:** ![StevanLECO51061](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@StevanLECO51061](https://forums.knack.com/u/StevanLECO51061)\
**Post date:** [September 7, 2016, 8:19am UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138/8 "2016-09-07T08:19:28Z")

</div>

Then you can set validation rule in your DB object

Just select either one of the 2 fields and set validation rule :&nbsp;

When "field 1" "is blank"

When "field 2" "is blank"

Show message : "please fill at least 1 field"

---

<div class="post-metadata">

**Author:** ![Markus91352](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Markus91352](https://forums.knack.com/u/Markus91352)\
**Post date:** [September 7, 2016, 7:42am UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138/9 "2016-09-07T07:42:20Z")

</div>

Thank you for your reply, my scenario is, that ONE of both are required, not both. In Data I can either set both to required or none or just one but that doesn't solve the problem.  
I need to do custom validation (another thing is that the name field gets validated by knack if only first or last name is filled, so there it is the exact opposite) in order to accept the form if only one of the two fields are filled, but reject it, if none of them are filled.

---

<div class="post-metadata">

**Author:** ![StevanLECO51061](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@StevanLECO51061](https://forums.knack.com/u/StevanLECO51061)\
**Post date:** [September 7, 2016, 7:23am UTC](https://forums.knack.com/t/prevent-form-submit-via-javascript/10138/10 "2016-09-07T07:23:40Z")

</div>

Hi.

In data \> object, you can set the required field option \> settings as "required".

I think it will solve your pb
