You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I wanted to share a solution for getting Netlify forms to work with AstroWind. My goal was to fix the "empty submission" problem without editing the theme's core Contact.astro widget, so my changes won't get overwritten by future theme updates.
The Problem:
When using the default Contact.astro widget, Netlify submissions work, but the notification email is empty.
The Solution:
Instead of modifying the theme files, I created a new, separate widget just for my Netlify form. This new component is self-contained and renders all its fields directly, which Netlify can parse.
Here are the two steps to do it:
Step 1: Create a new custom widget file
I created a new file at src/components/widgets/NetlifyForm.astro. This component is a copy of the original Contact.astro widget, but I've modified it to render the form fields directly instead of using <FormContainer />.
---// This is a new custom widget, e.g., src/components/widgets/NetlifyForm.astro// It's based on the theme's 'Contact.astro' but renders fields directly.importHeadlinefrom'~/components/ui/Headline.astro';importWidgetWrapperfrom'~/components/ui/WidgetWrapper.astro';importtype { ContactasProps } from'~/types'; // We can reuse the existing typeconst { title =awaitAstro.slots.render('title'), subtitle =awaitAstro.slots.render('subtitle'), tagline =awaitAstro.slots.render('tagline'), inputs, textarea, disclaimer, button, description, id, isDark =false, classes = {}, bg =awaitAstro.slots.render('bg'),} =Astro.props;---
<WidgetWrapperid={id}isDark={isDark}containerClass={`max-w-7xl mx-auto ${classes?.container??''}`}bg={bg}>
<Headlinetitle={title}subtitle={subtitle}tagline={tagline} />
{inputs&& (
<divclass="flex flex-col max-w-xl mx-auto rounded-lg backdrop-blur border border-gray-200 dark:border-gray-700 bg-white dark:bg-slate-900 shadow p-4 sm:p-6 lg:p-8 w-full">
<formname="custom-contact-form"method="POST"action="/success"data-netlify="true"netlify-honeypot="bot-field"class="w-full"
>
<inputtype="hidden"name="form-name"value="custom-contact-form" />
<divstyle="display:none;">
<label>Don’t fill this out if you’re human: <inputname="bot-field" /></label>
</div>
{inputs.map((input) => (
<divclass="mb-6">
<labelclass="block font-medium text-sm"for={input.name}>
{input.label}
</label>
<inputtype={input.type}name={input.name}id={input.name}placeholder={input.placeholder||''}autocomplete="on"class="block bg-white border border-gray-200 dark:bg-slate-900 dark:border-gray-700 px-4 py-3 rounded-lg text-md w-full"
/>
</div>
))}{textarea&& (
<div>
<labelclass="block font-medium text-sm"for={textarea.name}>
{textarea.label}
</label>
<textareaname={textarea.name}id={textarea.name}rows="4"class="block bg-white border border-gray-200 dark:bg-slate-900 dark:border-gray-700 px-4 py-3 rounded-lg text-md w-full"
></textarea>
</div>
)}
<divclass="grid mt-10">
<buttonclass="btn-primary"type="submit">
{button?.text||'Contact us'}
</button>
</div>
{description&& <pclass="mt-4 text-sm">{description}</p>}{disclaimer&& <pclass="mt-4 text-sm">{disclaimer}</p>}
</form>
</div>
)
}
</WidgetWrapper>
Step 2: Use your new widget on a page (e.g., src/pages/contact.astro)
Now, instead of calling <ContactUs />, you just call your new <NetlifyForm /> component. Make sure to pass the name property to the textarea object.
---importLayoutfrom'~/layouts/PageLayout.astro';// 1. Import your new custom widgetimportNetlifyFormfrom'~/components/widgets/NetlifyForm.astro';const metadata = { title: 'Contact',};---
<Layoutmetadata={metadata}>
<NetlifyFormid="form"title="Get in Touch"subtitle="You can use the form below to contact us directly."inputs={[
{
type: 'text',
name: 'name',
label: 'Name',
},
{
type: 'email',
name: 'email',
label: 'Email',
},
{
type: 'tel',
name: 'phone',
label: 'Phone Number',
},
]}textarea={{
label: 'Message',
name: 'message'// <-- This 'name' property is crucial!
}}
/>
</Layout>
By doing it this way, you get a working Netlify form, and you never have to worry about your changes being deleted when you update the AstroWind theme.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I wanted to share a solution for getting Netlify forms to work with AstroWind. My goal was to fix the "empty submission" problem without editing the theme's core
Contact.astrowidget, so my changes won't get overwritten by future theme updates.The Problem:
When using the default
Contact.astrowidget, Netlify submissions work, but the notification email is empty.The Solution:
Instead of modifying the theme files, I created a new, separate widget just for my Netlify form. This new component is self-contained and renders all its fields directly, which Netlify can parse.
Here are the two steps to do it:
Step 1: Create a new custom widget file
I created a new file at
src/components/widgets/NetlifyForm.astro. This component is a copy of the originalContact.astrowidget, but I've modified it to render the form fields directly instead of using<FormContainer />.src/components/widgets/NetlifyForm.astro(Full Code)Step 2: Use your new widget on a page (e.g.,
src/pages/contact.astro)Now, instead of calling
<ContactUs />, you just call your new<NetlifyForm />component. Make sure to pass thenameproperty to thetextareaobject.By doing it this way, you get a working Netlify form, and you never have to worry about your changes being deleted when you update the AstroWind theme.
Hope this helps!
Beta Was this translation helpful? Give feedback.
All reactions