如何在JavaScript中向URL传递未编码的邮箱字符串?——HubSpot表单跳转URL编码问题咨询
Hey there! I see exactly what's going on here—your email address is getting URL-encoded (with @ turning into %40) when redirecting to your Typeform, and you need the raw, unmodified email for that hidden field. Let’s fix this quickly.
The Root Cause
Looking at your code, you’re using encodeURIComponent() on every field, including the email. This function converts special characters like @ into URL-safe equivalents, which is useful for most fields, but Typeform needs the original email format here.
The Solution
Just remove the encodeURIComponent() wrapper from the email variable in your redirect line. Keep encoding for all other fields—this prevents issues with spaces, accents, or special characters that could break the URL structure.
Here’s the modified redirect code snippet:
window.location = "[URL TO REDIRECT TO HERE]?firstName=" + encodeURIComponent( firstname ) +"&lastName=" + encodeURIComponent( lastname ) +"&email=" + email + "&phone=" + encodeURIComponent( phone ) + "&language=" + encodeURIComponent( lang );
Quick Checks After Making the Change
- Test the form submission to confirm the email appears with the
@symbol (not%40) in your Typeform’s hidden field. - Double-check that other fields (like names with spaces or accented characters) still pass through correctly—their encoding is still intact to handle those edge cases.
内容的提问来源于stack exchange,提问作者Ry_iu

