Reputation: 34093
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.
Upvotes: 0
Views: 57
Reputation: 3406
use name tag in your input
e.g.
<input name="comment" type="text" defaultValue="Bob"/>
Upvotes: 2