formsreactjsenctype

Track submit event of form with encType=multipart/form-data


I noticed that the function assigned in the action tag is being evaluated every time the form changes. I want to do something like this to capture form submissions:

      <form className='input-form'
        encType='multipart/form-data'
        action={this.getRequestUrl()}
        method='post'
        onSubmit={this.trackFormSubmission()}>

but it appears that the trackFormSubmission() is being evaluated on form change as well.

I'm using React.js if that's helpful.


Solution

  • You call this.trackFormSubmission every time the render method gets called.

    You should change

    onSubmit={this.trackFormSubmission()}>
    

    to

    onSubmit={this.trackFormSubmission}>