fix: form block always shows fields; mailto fallback when no endpoint
This commit is contained in:
+14
-12
@@ -420,20 +420,22 @@ def render_blocks(blocks, site, page, entries):
|
||||
elif typ=='form':
|
||||
btn=escape(resolve('button_text','Contact Us'));href=safe_href(resolve('button_href','/contact-us/'))
|
||||
form_endpoint=site.get('settings',{}).get('form_endpoint','')
|
||||
email=site.get('settings',{}).get('email','') or site.get('email','') or ''
|
||||
if form_endpoint and str(form_endpoint).startswith('https://'):
|
||||
form_html=(
|
||||
f'<div class="sf-form-card"><h2 class="sf-form-title">{title}</h2><p class="sf-form-text">{desc}</p>'
|
||||
f'<form class="sf-form-grid" action="{escape(str(form_endpoint),quote=True)}" method="POST">'
|
||||
f'<div class="sf-form-field"><label>Your Name *</label><input name="name" required maxlength="200" autocomplete="name"></div>'
|
||||
f'<div class="sf-form-field"><label>Email *</label><input name="email" type="email" required maxlength="200" autocomplete="email"></div>'
|
||||
f'<div class="sf-form-field"><label>Phone / WhatsApp</label><input name="phone" maxlength="50" autocomplete="tel"></div>'
|
||||
f'<div class="sf-form-field sf-form-full"><label>Message *</label><textarea name="message" required maxlength="5000" rows="4"></textarea></div>'
|
||||
f'<input name="website" tabindex="-1" autocomplete="off" class="sf-honeypot" aria-hidden="true" style="position:absolute;left:-9999px">'
|
||||
f'<button class="sf-button sf-form-submit" type="submit">Send Inquiry →</button></form></div>')
|
||||
action=escape(str(form_endpoint),quote=True);method='POST'
|
||||
elif email:
|
||||
action=f'mailto:{escape(email)}?subject=Inquiry from website';method='POST'
|
||||
else:
|
||||
form_html=(f'<div class="sf-form-card sf-form-fallback"><h2 class="sf-form-title">{title}</h2><p class="sf-form-text">{desc}</p>'
|
||||
f'<p class="sf-form-note">Configure an external form endpoint in site settings to enable this form.</p>'
|
||||
f'<a class="sf-button" href="{href}">{btn} →</a></div>')
|
||||
action=href;method='GET'
|
||||
form_html=(
|
||||
f'<div class="sf-form-card"><h2 class="sf-form-title">{title}</h2><p class="sf-form-text">{desc}</p>'
|
||||
f'<form class="sf-form-grid" action="{action}" method="{method}">'
|
||||
f'<div class="sf-form-field"><label>Your Name *</label><input name="name" required maxlength="200" autocomplete="name" placeholder="John Smith"></div>'
|
||||
f'<div class="sf-form-field"><label>Email *</label><input name="email" type="email" required maxlength="200" autocomplete="email" placeholder="you@company.com"></div>'
|
||||
f'<div class="sf-form-field"><label>Phone / WhatsApp</label><input name="phone" maxlength="50" autocomplete="tel" placeholder="+86 ..."></div>'
|
||||
f'<div class="sf-form-field sf-form-full"><label>Message *</label><textarea name="message" required maxlength="5000" rows="4" placeholder="Tell us your product requirements, quantity and destination port."></textarea></div>'
|
||||
f'<input name="website" tabindex="-1" autocomplete="off" class="sf-honeypot" aria-hidden="true" style="position:absolute;left:-9999px">'
|
||||
f'<button class="sf-button sf-form-submit" type="submit">Send Inquiry →</button></form></div>')
|
||||
parts.append(start+form_html+end)
|
||||
elif typ=='layout':
|
||||
columns=block['columns'];gap=block.get('gap',24)
|
||||
|
||||
Reference in New Issue
Block a user