How to pass data through amp-form?
See original GitHub issueI have user information form. The form is validated using custom validation amp-form. My xhr-action attributes was pointing to my API url. When I submit my form with POST, my api returns nothing because req.body shows empty. Previously I’m using normal form action is working fine.
'/api/submit': { post: function(req, res){ console.log(req.body); } }
form(method="POST", action-xhr!='/api/submit/' + post_form_id + '?_csrf=' + csrf , target="_top", data-form-id=post_form_id, custom-validation-reporting="show-all-on-submit")
input.form-control.name(
type="text",
title="Name is required (Maximum 20 characters only)",
name="inputNameField",
placeholder="Full name*",
id="namefield"
required,
pattern="^[a-zA-Z \-\.\@\']{1,20}$")
input(type="submit", value="Submit", class="btn btn-block btn-black")
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Example: <amp-form> - amp.dev
The amp-form extension allows the usage of forms and input fields in an AMP ... It's possible to show custom success or error...
Read more >How to Manage Data Collected via AMP Forms - Yespo
Go to your account in our service and open the corresponding email with the AMP form. Click ϟHTML to open the settings. Insert...
Read more >Implementing AMP Forms from Start to Finish with amp-form ...
Learn how to implement forms in AMP using practical examples such as submitting a search on a blog and collecting newsletter subscribers.
Read more >Post an amp-form with a templated url - Stack Overflow
You can't change the URL directly, but amp-form will append your input field values to the URL as query parameters. This form:
Read more >How to develop & implement AMP forms on AMP pages
<script async custom-element="amp-form" ... this makes the browser to send the data using Fetch API when available, and fallback to XMLHttpRequest API for ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I got the same problem until I found amp-form send all data of xhr request in enctype=“multipart/form-data”. If the server is not properly configured, there is a good chance body will remain empty in this condition.
I hope this help.
Closing as it seems the bug is related to incorrect server-side implementation. Note that we are planning to support other
enctype
s foramp-form
in https://github.com/ampproject/amphtml/issues/7607