I wrote a simple form. For some reason, the form sends always GET requests instead of POST.
CODE EXAMPLE
<form action="{{ url_for('home') }}" method="post">
<div class="row">
<div class="col-sm-12">
<input type="text" required dir="rtl" name="name" class="form-control" id="Name" placeholder=" שם ">
</div>
<div class="col-sm-12">
<input type="tel" required dir="rtl" name="phone" class="form-control" id="Phone" placeholder=" פלאפון ">
</div>
<div class="col-sm-12">
<input type="email" dir="rtl" name="email" class="form-control" id="Email" placeholder=" דוא'ל ">
</div>
<div class="col-sm-12">
<textarea class="form-control" dir="rtl" name="text" rows="5" id="Message" placeholder=" הודעה "></textarea>
</div>
<div class="col-sm-12 col-md-12 c-c-padding">
<button type="submit" name="send" id="contact_submit" class="btn btn-dm"> שלח </button>
</div>
</div>
</form>
SERVER SIDE
@app.route('/', methods=["GET", "POST"])
def home():
print(request.method)
if request.method == 'POST':
name = request.form['name']
phone = request.form['phone']
email = request.form['email']
print(name + phone + email)
if phone:
requests.post('DOMAIN',
auth=("api", 'API'),
data={"from": "Email",
"to": ["email"],
"bcc": "",
"subject": " ",
"text": """ Name: {}
Phone: {}
Email: {} """.format(name, phone, email)})
flash(' welldone ', 'success')
return redirect(url_for('home'))
else:
flash(' phone ', 'warning')
return redirect(url_for('home'))
return render_template('index.html')
After I press the 'submit' button. As I said, it sends GET request instead of a POST. Then something weird happens. It injects 'index.html' into the form - and what happens, is that I have a website inside the website.
First, what should I do to fix the problem of sending POST request instead of GET request. Second, why 'render_template()' injects the HTML into the form? Instead render the whole page?