content logo

React Forms:

Dynamic React Form with Text and Email Validations

As you can see, in this post we have prepared a simple and at the same time practical form. You can use this form to get information from the user and register him. You can also use this form to record feedback from your website audience. This form is simplified using React. Button and. The border of this form is turquoise. In this form, there is a radio button and a text area and a drop-down list.

#

Submission Form Code

#

React Form Generation

#

React Form Elements

#

React Text Validation

#

React HTML Form

<!-- This script got from frontendfreecode.com -->
<div class="react-form-container"></div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
html {
  font-size: 16px;
}
body {
  font: 100%/1.414 sans-serif;
}
form {
  margin-right: auto;
  margin-left: auto;
  max-width: 320px;
  padding: 30px;
  border: 3px #3fc1c9 solid;
}
fieldset {
  padding: 0;
  margin: 0;
  border: 0;
}
fieldset + fieldset {
  margin-top: 24px;
}
label {
  margin-bottom: 8px;
  display: block;
  color: #2b2e4a;
}
input:not([type=checkbox]):not([type=radio]),
select,
textarea {
  padding: 8px;
  width: 100%;
  border-top: 0;
  border-right: 0;
  border-bottom: 1px solid #bdc3c7;
  border-left: 0;
  transition: border-bottom-color 0.15s ease-in;
}
input:not([type=checkbox]):not([type=radio]):focus,
select:focus,
textarea:focus {
  outline: 0;
  border-bottom-color: #3fc1c9;
}
input[type=checkbox],
input[type=radio] {
  margin-right: 8px;
}
textarea {
  resize: vertical;
}
button {
  margin-right: auto;
  margin-left: auto;
  display: block;
  padding: 8px 16px;
  font-size: 16px;
  color: #fff;
  background-color: #3fc1c9;
  border: 0;
  border-radius: 2px;
  cursor: pointer;
  transition: background-color 0.15s ease-in;
}
button:focus:active {
  background-color: #31a7ae;
}
button:focus {
  outline: 0;
}
button:hover {
  background-color: #7bd4da;
}
const formContainer = document.querySelector('.react-form-container');
class Button extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement("button", {
        type: this.props.type || 'button',
        value: this.props.value || null },
      this.props.text)));
  }}
;
class Datalist extends React.Component {
  render() {
    const dataOptions = this.props.options.split(', ');
    const dataOptionsList = dataOptions.map((dataOption, index) => {
      return /*#__PURE__*/React.createElement("option", { key: index, value: dataOption });
    });
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement(Label, {
        hasLabel: this.props.hasLabel,
        htmlFor: this.props.htmlFor,
        label: this.props.label }), /*#__PURE__*/
      React.createElement("input", { list: this.props.htmlFor }), /*#__PURE__*/
      React.createElement("datalist", {
        defaultValue: "",
        id: this.props.htmlFor,
        name: this.props.name || null,
        required: this.props.required || null }, /*#__PURE__*/
      React.createElement("option", { value: "", disabled: true }, "Select one option"),
      dataOptionsList)));
  }}
;
class Checkbox extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement("label", {
        htmlFor: this.props.htmlFor,
        label: this.props.label }, /*#__PURE__*/
      React.createElement("input", {
        id: this.props.htmlFor,
        name: this.props.name || null,
        required: this.props.required || null,
        type: "checkbox" }),
      this.props.label)));
  }}
class Label extends React.Component {
  render() {
    if (this.props.hasLabel === 'true') {
      return /*#__PURE__*/React.createElement("label", { htmlFor: this.props.htmlFor }, this.props.label);
    }
  }}
class Input extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement(Label, {
        hasLabel: this.props.hasLabel,
        htmlFor: this.props.htmlFor,
        label: this.props.label }), /*#__PURE__*/
      React.createElement("input", {
        id: this.props.htmlFor,
        max: this.props.max || null,
        min: this.props.min || null,
        name: this.props.name || null,
        placeholder: this.props.placeholder || null,
        required: this.props.required || null,
        step: this.props.step || null,
        type: this.props.type || 'text' })));
  }}
class Radio extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement("label", {
        htmlFor: this.props.htmlFor,
        label: this.props.label }, /*#__PURE__*/
      React.createElement("input", {
        id: this.props.htmlFor,
        name: this.props.name || null,
        required: this.props.required || null,
        type: "radio" }),
      this.props.label)));
  }}
class Select extends React.Component {
  render() {
    // Get all options from option prop
    const selectOptions = this.props.options.split(', ');
    // Generate list of options
    const selectOptionsList = selectOptions.map((selectOption, index) => {
      return /*#__PURE__*/React.createElement("option", { key: index, value: index }, selectOption);
    });
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement(Label, {
        hasLabel: this.props.hasLabel,
        htmlFor: this.props.htmlFor,
        label: this.props.label }), /*#__PURE__*/
      React.createElement("select", {
        defaultValue: "",
        id: this.props.htmlFor,
        name: this.props.name || null,
        required: this.props.required || null }, /*#__PURE__*/
      React.createElement("option", { value: "", disabled: true }, "Select one option"),
      selectOptionsList)));
  }}
;
class Textarea extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement(Label, {
        hasLabel: this.props.hasLabel,
        htmlFor: this.props.htmlFor,
        label: this.props.label }), /*#__PURE__*/
      React.createElement("textarea", {
        cols: this.props.cols || null,
        id: this.props.htmlFor,
        name: this.props.name || null,
        required: this.props.required || null,
        rows: this.props.rows || null })));
  }}
;
class Form extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("form", { method: "", action: "" }, /*#__PURE__*/
      React.createElement(Input, {
        hasLabel: "true",
        htmlFor: "textInput",
        label: "Text input",
        required: "true",
        type: "text" }), /*#__PURE__*/
      React.createElement(Input, {
        hasLabel: "true",
        htmlFor: "emailInput",
        label: "Email input",
        required: "true",
        type: "email" }), /*#__PURE__*/
      React.createElement(Input, {
        hasLabel: "true",
        htmlFor: "numberInput",
        label: "Number input",
        required: "true",
        type: "number",
        min: "0.5",
        max: "100",
        step: "0.5" }), /*#__PURE__*/
      React.createElement(Input, {
        hasLabel: "true",
        htmlFor: "passwordInput",
        label: "Password input",
        required: "true",
        type: "password" }), /*#__PURE__*/
      React.createElement(Select, {
        hasLabel: "true",
        htmlFor: "select",
        label: "Select",
        options: "one, two, three, option four, five",
        required: "true" }), /*#__PURE__*/
      React.createElement(Datalist, {
        hasLabel: "true",
        htmlFor: "datalist",
        label: "Datalist",
        options: "Chrome, Edge, Firefox, Internet Explorer, Opera, Safari, Vivaldi",
        required: "true" }), /*#__PURE__*/
      React.createElement(Textarea, {
        hasLabel: "true",
        htmlFor: "textarea",
        label: "Textarea",
        required: "true" }), /*#__PURE__*/
      React.createElement(Checkbox, {
        hasLabel: "true",
        htmlFor: "checkbox",
        label: "Checkbox",
        required: "true" }), /*#__PURE__*/
      React.createElement(Radio, {
        hasLabel: "true",
        htmlFor: "radioOne",
        label: "Radio one",
        name: "radios",
        required: "true" }), /*#__PURE__*/
      React.createElement(Radio, {
        hasLabel: "true",
        htmlFor: "radioTwo",
        label: "Radio two",
        name: "radios",
        required: "true" }), /*#__PURE__*/
      React.createElement(Button, {
        type: "submit",
        value: "submit",
        text: "Send form" })));
  }}
ReactDOM.render( /*#__PURE__*/React.createElement(Form, null), formContainer);
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js'></script>
<style>
html {
  font-size: 16px;
}
body {
  font: 100%/1.414 sans-serif;
}
form {
  margin-right: auto;
  margin-left: auto;
  max-width: 320px;
  padding: 30px;
  border: 3px #3fc1c9 solid;
}
fieldset {
  padding: 0;
  margin: 0;
  border: 0;
}
fieldset + fieldset {
  margin-top: 24px;
}
label {
  margin-bottom: 8px;
  display: block;
  color: #2b2e4a;
}
input:not([type=checkbox]):not([type=radio]),
select,
textarea {
  padding: 8px;
  width: 100%;
  border-top: 0;
  border-right: 0;
  border-bottom: 1px solid #bdc3c7;
  border-left: 0;
  transition: border-bottom-color 0.15s ease-in;
}
input:not([type=checkbox]):not([type=radio]):focus,
select:focus,
textarea:focus {
  outline: 0;
  border-bottom-color: #3fc1c9;
}
input[type=checkbox],
input[type=radio] {
  margin-right: 8px;
}
textarea {
  resize: vertical;
}
button {
  margin-right: auto;
  margin-left: auto;
  display: block;
  padding: 8px 16px;
  font-size: 16px;
  color: #fff;
  background-color: #3fc1c9;
  border: 0;
  border-radius: 2px;
  cursor: pointer;
  transition: background-color 0.15s ease-in;
}
button:focus:active {
  background-color: #31a7ae;
}
button:focus {
  outline: 0;
}
button:hover {
  background-color: #7bd4da;
}
</style>

</head>
<body>
<div class="react-form-container"></div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
const formContainer = document.querySelector('.react-form-container');
class Button extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement("button", {
        type: this.props.type || 'button',
        value: this.props.value || null },
      this.props.text)));
  }}
;
class Datalist extends React.Component {
  render() {
    const dataOptions = this.props.options.split(', ');
    const dataOptionsList = dataOptions.map((dataOption, index) => {
      return /*#__PURE__*/React.createElement("option", { key: index, value: dataOption });
    });
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement(Label, {
        hasLabel: this.props.hasLabel,
        htmlFor: this.props.htmlFor,
        label: this.props.label }), /*#__PURE__*/
      React.createElement("input", { list: this.props.htmlFor }), /*#__PURE__*/
      React.createElement("datalist", {
        defaultValue: "",
        id: this.props.htmlFor,
        name: this.props.name || null,
        required: this.props.required || null }, /*#__PURE__*/
      React.createElement("option", { value: "", disabled: true }, "Select one option"),
      dataOptionsList)));
  }}
;
class Checkbox extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement("label", {
        htmlFor: this.props.htmlFor,
        label: this.props.label }, /*#__PURE__*/
      React.createElement("input", {
        id: this.props.htmlFor,
        name: this.props.name || null,
        required: this.props.required || null,
        type: "checkbox" }),
      this.props.label)));
  }}
class Label extends React.Component {
  render() {
    if (this.props.hasLabel === 'true') {
      return /*#__PURE__*/React.createElement("label", { htmlFor: this.props.htmlFor }, this.props.label);
    }
  }}
class Input extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement(Label, {
        hasLabel: this.props.hasLabel,
        htmlFor: this.props.htmlFor,
        label: this.props.label }), /*#__PURE__*/
      React.createElement("input", {
        id: this.props.htmlFor,
        max: this.props.max || null,
        min: this.props.min || null,
        name: this.props.name || null,
        placeholder: this.props.placeholder || null,
        required: this.props.required || null,
        step: this.props.step || null,
        type: this.props.type || 'text' })));
  }}
class Radio extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement("label", {
        htmlFor: this.props.htmlFor,
        label: this.props.label }, /*#__PURE__*/
      React.createElement("input", {
        id: this.props.htmlFor,
        name: this.props.name || null,
        required: this.props.required || null,
        type: "radio" }),
      this.props.label)));
  }}
class Select extends React.Component {
  render() {
    // Get all options from option prop
    const selectOptions = this.props.options.split(', ');
    // Generate list of options
    const selectOptionsList = selectOptions.map((selectOption, index) => {
      return /*#__PURE__*/React.createElement("option", { key: index, value: index }, selectOption);
    });
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement(Label, {
        hasLabel: this.props.hasLabel,
        htmlFor: this.props.htmlFor,
        label: this.props.label }), /*#__PURE__*/
      React.createElement("select", {
        defaultValue: "",
        id: this.props.htmlFor,
        name: this.props.name || null,
        required: this.props.required || null }, /*#__PURE__*/
      React.createElement("option", { value: "", disabled: true }, "Select one option"),
      selectOptionsList)));
  }}
;
class Textarea extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", null, /*#__PURE__*/
      React.createElement(Label, {
        hasLabel: this.props.hasLabel,
        htmlFor: this.props.htmlFor,
        label: this.props.label }), /*#__PURE__*/
      React.createElement("textarea", {
        cols: this.props.cols || null,
        id: this.props.htmlFor,
        name: this.props.name || null,
        required: this.props.required || null,
        rows: this.props.rows || null })));
  }}
;
class Form extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("form", { method: "", action: "" }, /*#__PURE__*/
      React.createElement(Input, {
        hasLabel: "true",
        htmlFor: "textInput",
        label: "Text input",
        required: "true",
        type: "text" }), /*#__PURE__*/
      React.createElement(Input, {
        hasLabel: "true",
        htmlFor: "emailInput",
        label: "Email input",
        required: "true",
        type: "email" }), /*#__PURE__*/
      React.createElement(Input, {
        hasLabel: "true",
        htmlFor: "numberInput",
        label: "Number input",
        required: "true",
        type: "number",
        min: "0.5",
        max: "100",
        step: "0.5" }), /*#__PURE__*/
      React.createElement(Input, {
        hasLabel: "true",
        htmlFor: "passwordInput",
        label: "Password input",
        required: "true",
        type: "password" }), /*#__PURE__*/
      React.createElement(Select, {
        hasLabel: "true",
        htmlFor: "select",
        label: "Select",
        options: "one, two, three, option four, five",
        required: "true" }), /*#__PURE__*/
      React.createElement(Datalist, {
        hasLabel: "true",
        htmlFor: "datalist",
        label: "Datalist",
        options: "Chrome, Edge, Firefox, Internet Explorer, Opera, Safari, Vivaldi",
        required: "true" }), /*#__PURE__*/
      React.createElement(Textarea, {
        hasLabel: "true",
        htmlFor: "textarea",
        label: "Textarea",
        required: "true" }), /*#__PURE__*/
      React.createElement(Checkbox, {
        hasLabel: "true",
        htmlFor: "checkbox",
        label: "Checkbox",
        required: "true" }), /*#__PURE__*/
      React.createElement(Radio, {
        hasLabel: "true",
        htmlFor: "radioOne",
        label: "Radio one",
        name: "radios",
        required: "true" }), /*#__PURE__*/
      React.createElement(Radio, {
        hasLabel: "true",
        htmlFor: "radioTwo",
        label: "Radio two",
        name: "radios",
        required: "true" }), /*#__PURE__*/
      React.createElement(Button, {
        type: "submit",
        value: "submit",
        text: "Send form" })));
  }}
ReactDOM.render( /*#__PURE__*/React.createElement(Form, null), formContainer);
</script>

</body>
</html>
Preview