0

Sometimes I just want to submit a "normal" form, but have the input fields in React (of styling reasons).

But the form doesn't seem to "see" the values of the input fields when submitting.

<form action="comments" method="post">
  <label>
    Name:
    <input
      className={styles.input}
      defaultValue="Bob"
      type="text"
      ref={this.input} />
  </label>
  <input type="submit" value="Submit" />
</form>

Is there a way to accomplish something like the above, i.e. posting a form without having to create an onSubmit event handler that referes to every single field in the form?

Ps. I'm aware that the default React way is to include state, but that increases the boilerplate code even more.

1 Answer 1

2

use name tag in your input

e.g.

<input name="comment" type="text" defaultValue="Bob"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.