Пустая форма для отправки формы Netlify с плагином response-final-form

Я использую response-final-form для разработки многостраничной формы мастера, но теперь застрял на отправке своих материалов в Netlify.

Netlify обнаружил мою форму, но при отправке не получает данные моей формы  введите описание изображения здесь

Я впервые использую Netlify для обработки отправки форм, поэтому я не уверен, что я делаю что-то не так на стороне Netlifys или на стороне response-final-forms.

важно я использую GATSBY

index.js

<Wizard onSubmit={onSubmit}>
<Wizard.Page>
    <div>
        <div>
            <label css={label}>> Name</label>
        </div>
        <Field
            autocomplete="off"
            css={input}
            name="Name"
            component="input"
            type="text"
            placeholder="$"
            validate={required}
        />
        <Error name="Name" />
    </div>
    <div>
        <div>
            <label css={label}>> Email</label>
        </div>
        <Field
            autocomplete="off"
            css={input}
            name="Email"
            component="input"
            type="email"
            placeholder="$"
            validate={required}
        />
        <Error name="Email" />
    </div>

    <div>
        <div>
            <label css={label}>> Social handle</label>
        </div>
        <Field
            autocomplete="off"
            css={input}
            name="Social"
            component="input"
            type="text"
            placeholder="$"
        />
        <Error name="Social" />
    </div>
</Wizard.Page>

<Wizard.Page>
    <div>
        <div>
            <label css={label}>> What can we do for you?</label>
        </div>
        <div>
            <label
                style={{
                    display: 'flex',
                    alignItems: 'center',
                    paddingTop: '0.5em',
                }}
            >
                <Field
                    css={checkbox}
                    onClick={play}
                    name="services"
                    component="input"
                    type="checkbox"
                    value="Shopify build"
                />{' '}
                <span css={checkboxlabel}>Shopify build</span>
            </label>
        </div>
        <div>
            <label style={{ display: 'flex', alignItems: 'center' }}>
                <Field
                    css={checkbox}
                    onClick={play}
                    name="services"
                    component="input"
                    type="checkbox"
                    value="pop-up store"
                />{' '}
                <span css={checkboxlabel}>Pop-up store</span>
            </label>
        </div>
        <div>
            <label style={{ display: 'flex', alignItems: 'center' }}>
                <Field
                    css={checkbox}
                    onClick={play}
                    name="services"
                    component="input"
                    type="checkbox"
                    value="WebVR"
                />{' '}
                <span css={checkboxlabel}>WebVR</span>
            </label>
        </div>
        <div>
            <label style={{ display: 'flex', alignItems: 'center' }}>
                <Field
                    css={checkbox}
                    onClick={play}
                    name="services"
                    component="input"
                    type="checkbox"
                    value="Website audit"
                />{' '}
                <span css={checkboxlabel}>Website audit</span>
            </label>
        </div>
        <div>
            <label style={{ display: 'flex', alignItems: 'center' }}>
                <Field
                    css={checkbox}
                    onClick={play}
                    name="services"
                    component="input"
                    type="checkbox"
                    value="Asset creation"
                />{' '}
                <span css={checkboxlabel}>Asset creation</span>
            </label>
        </div>
        <div>
            <label style={{ display: 'flex', alignItems: 'center' }}>
                <Field
                    css={checkbox}
                    onClick={play}
                    name="services"
                    component="input"
                    type="checkbox"
                    value="Other"
                />{' '}
                <span css={checkboxlabel}>Other</span>
            </label>
        </div>
    </div>

    <div>
        <div style={{ paddingTop: '1em' }}>
            <label css={label}>> Budget</label>
        </div>
        <Field css={budget} name="Budget" component="select">
            <option />
            <option value="UNDER > $3000">UNDER > $3000</option>
            <option value="$3000 - $10000">$3000 - $10000</option>
            <option value="$10000 - $15000">$10000 - $15000</option>
            <option value="$15000 - $25000">$15000 - $25000</option>
            <option value="$25000+">$25000+</option>
        </Field>
        <Error name="budget" />
    </div>
</Wizard.Page>
<Wizard.Page>
    <div>
        <div>
            <label css={label}>> Message</label>
        </div>
        <Field
            css={message}
            name="message"
            component="textarea"
            placeholder="$"
        />
        <Error name="message" />
    </div>
</Wizard.Page>

Wizard.js

    handleSubmit = values => {
    const { children, onSubmit } = this.props
    const { page } = this.state
    const isLastPage = page === React.Children.count(children) - 1
    if (isLastPage) {
        return onSubmit(values)
    } else {
        this.next(values)
    }
}



render() {
    const { children } = this.props
    const { page, values } = this.state
    const activePage = React.Children.toArray(children)[page]
    const isLastPage = page === React.Children.count(children) - 1
    
    return (
        <Form
            autocomplete="off"
            initialValues={values}
            validate={this.validate}
            onSubmit={this.handleSubmit}  
        >
            {({ handleSubmit, submitting, values }) => (
                <form name="notypo-services" method="POST" data-netlify="true" onSubmit={handleSubmit}>
                    {activePage}
                    <div className="buttons">
                        {page > 0 && (
                            <div onClick={this.previous}>
                                <PrevButton></PrevButton>
                            </div>
                        )}
                        {!isLastPage && (
                            <NextButton></NextButton>   
                        )}
                        {isLastPage && (
                            <div type="submit">
                                <SendButton></SendButton>
                            </div>
                        )}
                    </div>
                </form>
            )}
        </Form>
    )
}

person dehnm    schedule 14.10.2020    source источник


Ответы (2)


Ваш тег <form> должен иметь action, а предоставленные данные должны иметь пару _3 _-_ 4_:

<form name="notypo-services" 
      method="POST" 
      data-netlify="true" 
      action="/"
      onSubmit={handleSubmit}>

И ваши данные должны быть структурированы следующим образом:

form-name: "notypo-services"
Name: "Your typed name"
Email: "Your typed email"

Обратите внимание на значение form-name. Это обязательно.

Если у вас нет thank-you страницы, вы можете перенаправить действие на себя с помощью /.

Кроме того, я бы предложил добавить data-netlify-honeypot, чтобы избежать спама.

Вы можете проверить документация Netlify для получения дополнительной информации.

person Ferran Buireu    schedule 15.10.2020
comment
Привет! добавлено действие = / но он не отправил меня на страницу с благодарностью, и мои данные структурированы следующим образом: Бюджет: МЕНЬШЕ ›$ 3000 Электронная почта: [email protected] Имя: mitch Соцсети: mitch313123 сообщение: это тестовая отправка для службы переполнения стека: [создание активов] на основе моего console.log (значения) - person dehnm; 16.10.2020
comment
также до сих пор нет данных на стороне Netlifys - person dehnm; 16.10.2020
comment
В соответствии с тем, что вы сказали, нет поля form-name - person Ferran Buireu; 16.10.2020
comment
Хорошо, небольшая проблема. ‹Input type = hidden name = form-name value = notypo-services /› не обнаруживается в значениях. Итак, я попробовал - ‹Компонент поля = тип ввода = скрытое имя = имя-формы значение = notypo-services /› Но согласно документам response-final-form вы не можете добавлять значения в поля ввода (только флажки и радио) final-form.org/docs/react-final-form/types / FieldProps # value из-за этого я думаю, что Netlify и react-final-form могут быть несовместимы, по крайней мере, с тем, как я его настроил. - person dehnm; 17.10.2020
comment
Вы всегда можете манипулировать своим объектом данных перед его отправкой, чтобы добавить значение имени вашей формы. - person Ferran Buireu; 17.10.2020

после нескольких дней откладывания я наконец собрал это воедино

При отправке я передаю свои данные в скрытую форму, которая затем отправляется в Netlify (успешно)

handleSubmit = values => {
    const { children, onSubmit } = this.props
    const { page } = this.state
    const isLastPage = page === React.Children.count(children) - 1
    if (isLastPage) {
        document.getElementById("realFormName").value = "notypo-services";
        document.getElementById("realName").value = values.Name ;
        document.getElementById("realEmail").value =  values.Email;
        document.getElementById("realSocial").value =  values.Social;
        document.getElementById("realServices").value =  values.Services;
        document.getElementById("realBudget").value =  values.Budget;
        document.getElementById("realMessage").value =  values.Message;
        
        
        document.getElementById("myForm").submit() ;

        return false ;
    } else {
        this.next(values)
    }
}

<form id="myForm" name="notypo-services" method="POST" data-netlify="true" data-netlify-honeypot="bot-field" action="/" style={{display: 'none'}}>
     <input hidden="true" name="form-name" type="text" id="realFormName" />
     <input hidden="true" name="Name" type="text" id="realName" />
     <input hidden="true" name="Email" type="email" id="realEmail" />
     <input hidden="true" name="Social" type="text" id="realSocial" />
     <input hidden="true" name="Services" type="text" id="realServices" />
     <input hidden="true" name="Budget" type="text" id="realBudget" />
     <input hidden="true" name="Message" type="text" id="realMessage" />
            
     <input hidden="true" type="submit" value="Submit" />
</form>
person dehnm    schedule 21.10.2020