Site: https://brdchallenge.netlify.app/
I have built a quiz app in React which gives you a score and asks you to submit a form at the end. I have passed the score into an input text value using props and setState. The score shows up on the form in my app, but is not getting passed to netlify.
I am adding the score to my Form component like this (edited for clarity):
constructor(props) {
super(props);
this.state = {
fullname: '',
savedScore: this.props.saveScore
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange = e => {
this.setState({
[e.target.name]: e.target.value
});
};
handleSubmit = e => {
const form = e.currentTarget;
if (form.checkValidity() === true ) {
this.setState({
savedScore: this.props.saveScore
})
fetch("/", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: encode({ "form-name": "contact", ...this.state })
})
.catch(error => alert(error));
}
e.preventDefault();
};
render() {
return (
<form onSubmit={this.handleSubmit}>
<input type="hidden" name="form-name" value="contact" />
<input type="text" name="fullname" placeholder="Full name*" value={this.state.fullname} onChange={this.handleChange} />
<input type="text" id="score" name="score" value={this.state.savedScore}></input>
</form>
)
};
And I have a static html form:
<form name="contact" netlify netlify-honeypot="bot-field" hidden>
<input type="text" name="fullname" />
<input type="text" name="score" />
</form>
All my other fields show up except for this one. Any ideas?