简体   繁体   English

反应 CSS 表单验证

[英]react CSS form validation

While making a form on react I downloaded some libraries and copied some example I ultimately went with one I made my self but now my entire project has this validation that will stay no matter what I put in the project.在制作 react 表单时,我下载了一些库并复制了一些示例,我最终使用了我自己制作的一个,但现在我的整个项目都有这个验证,无论我在项目中放入什么,它都会保留下来。 Every time I click a button I get a tooltip and I have no idea how to control it.每次单击按钮时,我都会得到一个工具提示,但我不知道如何控制它。

Here is my code这是我的代码

import React, { useEffect } from 'react';
import axios from 'axios'

const FormRequest = () => {

   
    const formSubmitHandler = () => {
        
      console.log()
        }

    return (
        <div  >
            <div >
                <div >
                    <div>
                        <div>
                            <div></div>
                            <div></div>
                        </div>
                        <div>
                            <div></div>
                            <div></div>
                            <div></div>
                        </div>
                    </div>
                    <div >
                        <div >
                            <div >
                                <span>CONTACT</span>
                                <span>US</span>
                            </div>
    
                        </div>
                        <div >
                            <form  onSubmit={(formSubmitHandler)}>
                                <div >
                                    <input 
                                        placeholder="NAME"
                                        name="name"

                                        onChange={''} value={''} required />
                                </div>
                                <div >
                                    <input 
                                        type="email"
                                        onChange={''} value={''}
                                        placeholder="EMAIL"
                                        name="email"
                                        required />
                                </div>
                                <div >
                                    <input 

                                        placeholder="CONTACT NO"
                                        name="contact"
                                        onChange={''} value={''}
                                    />
                                </div>
                                <div >
                                    <select 
                                        placeholder="REASON"
                                        name="reasonForContact"
                                        onChange={''} value={'onForContact'}
                                        defaultValue="">

                                        <option disabled={true} value="">Reason for Contact</option>
                                        <option value="">apple</option>
                                        <option value="">coconut</option>
                                        <option selected value="coconut">cocnutn</option>
                                        <option value="mango">Mango</option>
                                    </select>

                                </div>
                                <div app-form-group >
                                    <input placeholder="MESSAGE"
                                        name="message"
                                        onChange={''} value={''} required
                                    />
                                </div>
                                <div >
                                    <div >
                                        <input
                                            type="checkbox"
                                            checked={ ''}
                                            onChange={''} value={''}

                                            name="acceptTerms"
                                            required />

                                        <p> Do you agree to us saving your details for future us?</p>
                                    </div>
                                </div>
                                <div >
                                    <button >CANCEL</button>
                                    <button >SEND</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>)
};

export default FormRequest;

Here is the output这是 output 在此处输入图像描述

The required attribute is the HTML attribute, to have the form validation for inputs like phone number, email and so on. required的属性是 HTML 属性,用于对电话号码、email 等输入进行表单验证。 You should know about this.你应该知道这件事。

Remove the "required" keyword from your input fields从输入字段中删除“必需”关键字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM