0

I have an html table calendar with the dates set to buttons. When a user clicks on the button, the button will redirect them to the appointments page. However, I need it to pass the value of the button, set to its respective date, to the appointments page as well so the user can book a meeting on that date.

<button type="button" value = "1" onclick="window.location.href='{{ url_for( 'appointments') }}';">1</button> 

I would like to pass the value "1" to /appointments page when I click the button but I do not know how to do so. Is it possible to do this? Im doing this on flask python.

Appointments.html

{% extends 'base.html' %} {% block body %} <div class="container"> <form method="POST" action="/appointments"> <h2>Appointments</h2> <p> {{ form.start.label }}<br> {{ form.start }} </p> <p> {{ form.end.label }}<br> {{ form.end }} </p> <p> {{ form.description.label }}<br> {{ form.description }} </p> <p> {{ form.guestName.label }}<br> {{ form.guestName }} </p> <input type="submit"> <!-- <button class = "btn btn btn-primary btn block" type="submit">Set up</button> --> </form> </div> <!-- /container --> {% endblock %} 

Appointment route:

@app.route('/appointments', methods=['GET', 'POST']) def appointments(): form = AddAppointment() if form.is_submitted(): startingTime = datetime.datetime.strptime( form.start.data, '%H:%M').time() endingTime = datetime.datetime.strptime(form.end.data, '%H:%M').time() print(startingTime, endingTime) appt = Appointments(starttime=form.start.data, endtime=form.end.data, description=form.description.data, guestName=form.guestName.data) print(appt) db.session.add(appt) db.session.commit() return redirect('/dashboard') return render_template('appoitments.html', form=form) 
2
  • We would need a lot more information to help you out. Check How to create a Minimal, Reproducible Example Commented May 3, 2020 at 0:41
  • Just added some more info to make it a bit clearer Commented May 3, 2020 at 0:47

1 Answer 1

1

A quick fix is to add a hidden input field to the form, i.e. <input type="hidden" name="<field_name>" value="1" />. See this answer.

If that doesn't work, you can use javascript with an xml request, usually promise-ified with axios or fetch, to send the form data. It might be overkill for what you're trying to do, though.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.