Passing Value Along With Form In Post Data In Django
Solution 1:
You should be able to simply add a hidden input to your form to capture the patient ID:
{% block content %}
<divclass="container"><h1>Patient Checkin</h1><h2>{{patient.first_name}} {{patient.last_name}}</h2></div><divclass="container"><formaction="{% url 'patientRecords:checkinsubmit' %}"method="POST"class="form"><inputtype="hidden"name="patient_id"value="{{patient.patient_id}}" />
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<buttontype="submit"class="btn btn-primary">Submit</button>
{% endbuttons %}
</form></div>
{% endblock %}
(Note this assumes that the patient ID is accessible from the patient_id
property of the patient
object.)
Then, in your CheckinSubmit
method, you can access this value via request.POST.get('patient_id')
Alternatively, it appears that your check in form loads with the patient ID in the URL. In your CheckinSubmit
method, you should be able to access this URL through the request.META.HTTP_REFERER
property. You could then parse the URL (e.g., using request.META.HTTP_REFERER.split('/')[len(request.META.HTTP_REFERER.split('/')) - 1]
to pull out the patient ID.
Solution 2:
Example
<formmethod="post"action = "{% url 'user_search_from_group' %}"><divclass="module-option clearfix"><divclass="input-append pull-left"><inputtype="hidden"name="groupname"value="{{ gpname }}" />
{% csrf_token %}
<inputtype="text"class="span3"placeholder="Filter by name"id="username3"name="username3"required><buttontype="submit"class="btn"name="submit"><iclass="icon-search"></i></button></div></div></form>
Here a hidden field is used to pass a value along form.
def user_search_from_group(request):
if request.method == 'POST':
username3 = request.POST.get('username3')
gname = request.POST.get('groupname')
Using request we are use the value inside view
Post a Comment for "Passing Value Along With Form In Post Data In Django"