How to Submit Forms and Save Data with React.js

class UserForm extends React.Component {
   constructor(props) {
      super(props);
      this.state = {username: ''};
      this.handleChange = this.handleChange.bind(this);
      this.handleSubmit = this.handleSubmit.bind(this);
   }
   handleChange(event) {
      this.setState({username: event.target.value});
   }
   handleFormSubmit(event) {
      console.log('username: ' + this.state.username);
      event.preventDefault();
   }
   render() {
      return (
         <form onSubmit={this.handleFormSubmit}>
            <label>
               Name:
               <input type="text" value={this.state.username} onChange={this.handleUsernameChange} />
            </label>
            <input type="submit" value="Submit" />
         </form>
      );
   }
}

4
8
Awgiedawgie 440220 points

                                    handleInputChange(event) {
&nbsp; &nbsp;const value = event.target.value;
&nbsp; &nbsp;const name = event.target.name;
&nbsp; &nbsp;this.setState({
&nbsp; &nbsp; &nbsp; [name]: value
&nbsp; &nbsp;});
}

4 (8 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to save form value in react how to read data when submitting form in react js react function to save form data react form to save form data save form data in react js formdata save form data in react js form send form data manually react how to save form values on input field after submit react how to send form data in react .js save form data in react store form data to post react how to post react form datat submit form and save to the database in react how to send a form data in react js How to have a save button for a form React.js how to send form data properly in react save form data in react js example of save entry in react form before form submit how to send form data in react js how to post new form-data in react js react save form data submit and save file in form react form data in react js save data from form react send form data in react js send form data react js How to get form data on submit in ReactJS how to all input field in form after submit in react js on submit print value in input using reactjs form using react js get form data after submit react js react get form values on submit react send form data getting for,m data from submit react show message on form submit in react reload page on form submit react react submit a form example how to submit form in reactjs and send data in json where to submit react form data form submit using react and node js reload page on submit react submit data react react get the values of input and submit react submit form data to api how to route to another page after submit form in reactjs How to Submit Forms and Save Data with React.js
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source