1

I have html form:

    <form id = "contactForm">
        <input type="text" name="name"></input>
        <input  type="text" name="phone"></input>
    </form>

I have Button and when I click it I am doing ajax post request:

$.post( "/send-form", $('#contactForm').serialize()

In chrome web inspector I can see that data is sent name=+gfdsfd&phone=89999enter image description here

This is my backend function I am using Flask,Python:

  @app.route("/send-form", methods=['POST'])
def send_form():
    name = phone = email = country = text = None
    data = request.data
    print request.data

And it prints empty string in my console. What can be the problem?

1 Answer 1

2

To access Flask's form data you should use the form attribute of the request object .

name=request.form['name']
data=request.form['phone'] 
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks god I've broken my brain trying to detect what's wrong!
But I still have a question. I used the wrong syntaxis above in my answer in another project and it worked.How can that be?
Could you post this 'other project' details ?
wait a few seconds I will make another question with details and post a link here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.