html - invalid value of multi input radio button - python

I have multi input type radio buttons on my page and when I submitted it, on the server side, that two values are exchanged, I have no idea how to debug it.
So here my code,
<div id="is_partial_time" class="form-group">
<label class="col-md-3 col-sm-4 control-label" for="is_partial_time">Would you accept a CDD or a replacement contract</label>
<div class="col-md-7 col-sm-8">
<div id="group_is_partial_time" class="btn-group" data-toggle="buttons">
<label class="btn btn-info">
<input type="radio" name="is_partial_time" value="true"/>Yes
</label>
<label class="btn btn-info active">
<input type="radio" name="is_partial_time" value="false" checked="checked"/>No
</label>
</div>
</div>
</div>
<div id="is_replacement_contract" class="form-group">
<label class="col-md-3 col-sm-4 control-label" for="is_replacement_contract">Would you accept a partial time?</label>
<div class="col-md-7 col-sm-8">
<div id="group_is_replacement_contract" class="btn-group" data-toggle="buttons">
<label class="btn btn-info">
<input type="radio" name="is_replacement_contract" value="true"/>Yes
</label>
<label class="btn btn-info active">
<input type="radio" name="is_replacement_contract" value="false" checked="checked"/>No
</label>
</div>
</div>
</div>
Example,
on the web form ():
I choose:
Would you accept a replacement contract? Yes
Would you accept a partial time? No
On the server side:
Would you accept a replacement contract? No
Would you accept a partial time? Yes
Info: I'm using python Flask.
Thank you.

Your <label ..> are at the wrong place. It should be
<div id="is_partial_time" class="form-group">
<label class="col-md-3 col-sm-4 control-label" for="is_partial_time">Would you accept a partial time?</label>
<div class="col-md-7 col-sm-8">
<div id="group_is_partial_time" class="btn-group" data-toggle="buttons">
<label class="btn btn-info">
<input type="radio" name="is_partial_time" value="true"/>Yes
</label>
<label class="btn btn-info active">
<input type="radio" name="is_partial_time" value="false" checked="checked"/>No
</label>
</div>
</div>
</div>
<div id="is_replacement_contract" class="form-group">
<label class="col-md-3 col-sm-4 control-label" for="is_replacement_contract">Would you accept a CDD or a replacement contract</label>
<div class="col-md-7 col-sm-8">
<div id="group_is_replacement_contract" class="btn-group" data-toggle="buttons">
<label class="btn btn-info">
<input type="radio" name="is_replacement_contract" value="true"/>Yes
</label>
<label class="btn btn-info active">
<input type="radio" name="is_replacement_contract" value="false" checked="checked"/>No
</label>
</div>
</div>
</div>

Related

Weasyprint render_to_string <weasyprint.HTML object at 0x7f6f944df190> 2 extra bytes in post.stringData array problem

I have an html template and I want to print a pdf with weayprint for it. However, I am getting the error "<weasyprint.HTML object at 0x7f6f944df190> 2 extra bytes in post.stringData array problem" that I mentioned in the title. I am sharing my views.py file and some of my html template.
views.py
def export_pdf(id):
print('export')
edit_ambulanceCase = CallCenter.objects.all()
html_string = render_to_string('forms/update_forms/pdf.html',{'PreCaseControl':edit_ambulanceCase})
print(html_string)
html = HTML(string=html_string)
print(html)
return HttpResponse(html.write_pdf('deneme.pdf'))
pdf.html
<main>
<div class="container-fluid px-4">
<div class="row justify-content-center">
<div class="col-lg-12">
<div class="card shadow-lg border-0 rounded-lg mt-5">
<div class="card-header"><h4 class="text-center font-weight-light my-4">Çağrı Merkezi Formu</h4></div>
<div class="card-body">
<form action="" method="POST">
{% csrf_token%}
<h3>Çağrıyı Yapan</h3>
<div class="row">
<div class="mb-3 col">
<label for="institution_name" class="form-label">KURUM ADI</label>
<input type="text" class="form-control" id="institution_name" name="institution_name" value="{{CallCenter.institution_name}}">
</div>
<div class="mb-3 col">
<label for="caller_username" class="form-label">ADI SOYADI</label>
<input type="text" class="form-control" id="caller_username" name="caller_username" value="{{CallCenter.caller_username}}">
</div>
</div>
<div class="row">
<div class="mb-3 col">
<label for="proximity" class="form-label">YAKINLIĞI</label>
<input type="text" class="form-control" id="proximity" name="proximity" value="{{CallCenter.proximity}}">
</div>
<div class="mb-3 col" data-type="control-phone">
<label for="caller_tel_no" class="form-label">TELEFON NUMARASI</label>
<input type="tel" class="form-control" id="caller_tel_no" name="caller_tel_no" value="{{CallCenter.caller_tel_no}}" data-component="phone" inputmode="text" maskvalue="(###) ###-####" val>
<label class="form-sub-label" style="min-height: 13px;" for="caller_tel_no_sub">Lütfen geçerli bir telefon numarası girin.</label>
</div>
</div>
<h3>Hasta</h3>
<div class="row">
<div class="mb-3 col">
<label for="patient_username" class="form-label">ADI SOYADI</label>
<input type="text" class="form-control" id="patient_username" name="patient_username" value="{{CallCenter.patient_username}}">
<label for="patient_age" class="form-label">YAŞ</label>
<input type="text" class="form-control" id="patient_age" name="patient_age" value="{{CallCenter.patient_age}}">
</div>
<div class="mb-3 col">
<label for="" class="form-label">CİNSİYET</label>
<div >
<input class="form-check-input" type="radio" id="male" name="gender" {% if CallCenter.gender == 'erkek' %} checked {%endif%} value="erkek">
<label for="male" class="form-label">Erkek</label>
</div>
<div>
<input class="form-check-input" type="radio" id="female" name="gender" {% if CallCenter.gender == 'kadın' %} checked {%endif%} value="kadın">
<label for="female" class="form-label">Kadın</label>
</div>
</div>
</div>
My html template continues as I have attached. It does not contain any other content. I couldn't include the whole thing because it was too long.

Receive array from HTML form in FastAPI

I'm trying to submit a form through post in FastAPI and get a form variable that is stored as a list. When I read back the value all I get is an empty list. There are several variables that will eventually be in list form but all I am trying to get at the moment is the array that holds the quantity values.
What am I doing wrong?
Here is my code:
Python Code
#app.post("/edit_bom")
def edit_bom(board_id: int = Form(...), quantity: list = Form(...)):
print("Editting BOM, board ID: " + str(board_id))
print("quantity: ", quantity)
return RedirectResponse(url=f"/get_bom_details/" + str(board_id), status_code=303)
HTML Code
<form method="post" action="/edit_bom" id="parent-form">
<div class="mb-3 row">
<div class="d-grid gap-2 col-2">
<button type="button" class="btn btn-outline-primary add-one-more"><i class="fas fa-fw fa-plus-square"></i> New Row</button>
</div>
<div class="d-grid gap-2 col-2">
<button type="submit" name="action" value="save-bom" class="btn btn-outline-success"><i class="fas fa-fw fa-check"></i> Save</button>
</div>
</div>
<div class="mb-3 row" id="header">
<label class="col-form-label col-sm-1 text-sm-end"></label>
<div class="col-sm-7">
<h3>Part Number</h3>
</div>
<div class="col-sm-2">
<h3>Quantity</h3>
</div>
<div class="input-group col">
<h3>Edit</h3>
</div>
<div class="input-group col">
<h3>Delete</h3>
</div>
</div>
<div class="mb-3 row bom-line-item copy-fields" id="entry">
<label class="col-form-label col-sm-1 text-sm-end child-row-label">1</label>
<div class="col-sm-7 child-outer">
<input type="text" name="part-name_1" id="0" class="form-control child-part-name" placeholder="Board Number" value="ISL73847SEHDEMO1ZB">
</div>
<div class="col-sm-2 child-outer">
<input type="number" name="quantity[]" id="0" class="form-control child-part-quantity" placeholder="Enter quantity" value="1">
</div>
<div class="input-group col child-outer">
<button id="btn-edit_1" class="btn btn-primary child-btn-edit" type="button"><i class="fas fa-fw fa-edit"></i></button>
</div>
<div class="input-group col child-outer">
<button id="btn-del_1" class="btn btn-danger child-btn-delete" type="button"><i class="fas fa-fw fa-ban"></i></button>
</div>
</div>
<div class="end-of-list" name="noOfRows" value="1"></div>
<input type="hidden" name="board_id" value="1">
</form>
My output in the command prompt:
Editting BOM, board ID: 1
quantity: []
Using the comment from #MatsLindh
I had to change the HTML element name from "quantity[]" to "quantity" and it works now.

How to get/Fetch Form data in django using cloud firestore?

Form picture
ID is been selected but I'm not getting the values in the form, please check my code files. See in the picture in URL of the browser, update/id is selected, the problem is values are not fetched in the form.
HTML:
<form id="task-form" name="myForm">
{% csrf_token %}
<div class="form-group">
<div class="row">
<div class="col">
<input type="text" class="form-control" id="task-building" placeholder="Building name" name="building" value="{{buildings.building}}">
</div>
<div class="col">
<input type="text" class="form-control" id="task-postal" placeholder="Postal Code" name="postalCode" value="{{buildings.postalCode}}">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">
<input type="text" class="form-control" id="task-town" placeholder="town" name="town" value="{{buildings.town}}">
</div>
<div class="col">
<input type="text" class="form-control" id="task-street" placeholder="Street" name="street" value="{{buildings.street}}">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">
<input type="text" class="form-control" id="task-house" placeholder="House No." name="houseNo" value="{{buildings.houseNo}}">
</div>
<div class="col">
<input type="text" class="form-control" id="task-info" placeholder="Additional Information" name="additionalInfo" value="{{buildings.additionalInfo}}">
</div>
</div>
</div>
<div class="text-center mt-3">
<button type="submit" id="btn-task-form" class="btn btn-primary ">UPDATE</button>
</div>
</form>
views.py
def update_Building(request, id):
docId = id;
context = {
'buildings': db.collection('Buildings').document(docId).get()
}
return render(request,"EmployeeAdmin/updateBuilding.html", context)
urls.py
path('update/<str:id>/',views.update_Building,name='update_Building'),

First Modal works, but second modal doesn't work

I have a table to display and in which i'm creating two buttons inside a column and each has its modals to be open.
Button 1 - "Update"; its modal is "modaledit" - doesn't work
Button 2 - "Generic Tech Skills"; its modal is "modalgts" - works fine
What I don't understand is that, when I Place the "modaledit's" code before "modalgts's" code. It works fine. Can somebody please try to help in this regard?
<thead class="text-center">
<tr>
<th>Employee ID</th>
<th>Name</th>
<th>Experience</th>
<th>Manager</th>
<th>Team</th>
<th>General Action</th>
<th>Enter Score</th>
</tr>
</thead>
<tbody id="myTable" class="text-center">
{% for row in employees %}
<tr>
<td>{{row.employee_id}}</td>
<td>{{row.name}}</td>
<td>{{row.experience}}</td>
<td>{{row.manager}}</td>
<td>{{row.team}}</td>
<td>
Edit
Generic Tech Skills
</td>
<td>
</td>
</tr>
</tbody>
<div id="modalgts{{row.employee_id}}" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title text-dark"> Enter Generic Tech Skills Score </h4>
</div>
<div class="modal-body">
<form action="{{url_for('gts')}}" method="POST">
<div class="form-group">
<label>Employee ID</label>
<input type="Number" class="form-control " name="employee_id" value="{{row.employee_id}}" readonly>
</div>
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" value="{{row.name}}">
<div class="form-group">
<label>Experience</label>
<select type="text" class="form-control" name="experience" value="{{row.experience}}">
<option selected>{{row.experience}}</option>
<option>Less than 3 years</option>
<option>3 to 6 Years</option>
<option>6 to 9 years</option>
<option>More than 9 Years</option>
</select>
</div>
<div class="form-group">
<label>Manager</label>
<select type="text" class="form-control" name="manager" value="{{row.manager}}">
<option selected>{{row.manager}}</option>
<option>Ravindra</option>
<option>Subash</option>
<option>Subhandh</option>
<option>Amulya</option>
<option>Dinesh</option>
</select>
</div>
<div class="form-group">
<label>Team</label>
<select class="form-control" name="team" value="{{row.team}}">
<option selected>{{row.team}}</option>
<option>SAN Engineering</option>
<option>Cloud Engineering</option>
<option>Hypervisor Systems Engineering</option>
<option>Automation Engineering</option>
</select>
</div>
<div class="form-group">
<button class="btn btn-outline-primary" type="submit">Update</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Modal Edit Employee-->
<div id="modaledit{{row.employee_id}}" class="modal hide fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title text-dark"> Update Employee </h4>
</div>
<div class="modal-body">
<form action="{{url_for('update')}}" method="POST">
<div class="form-group">
<label>Employee ID</label>
<input type="Number" class="form-control " name="employee_id" value="{{row.employee_id}}" readonly>
</div>
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" value="{{row.name}}">
<div class="form-group">
<label>Experience</label>
<select type="text" class="form-control" name="experience" value="{{row.experience}}">
<option selected>{{row.experience}}</option>
<option>Less than 3 years</option>
<option>3 to 6 Years</option>
<option>6 to 9 years</option>
<option>More than 9 Years</option>
</select>
</div>
<div class="form-group">
<label>Manager</label>
<select type="text" class="form-control" name="manager" value="{{row.manager}}">
<option selected>{{row.manager}}</option>
<option>Ravindra</option>
<option>Subash</option>
<option>Subhandh</option>
<option>Amulya</option>
<option>Dinesh</option>
</select>
</div>
<div class="form-group">
<label>Team</label>
<select class="form-control" name="team" value="{{row.team}}">
<option selected>{{row.team}}</option>
<option>SAN Engineering</option>
<option>Cloud Engineering</option>
<option>Hypervisor Systems Engineering</option>
<option>Automation Engineering</option>
</select>
</div>
<div class="form-group">
<button class="btn btn-outline-primary" type="submit">Update</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{% endfor %}
</table>
</div>

How to add a button in email input?

I am trying to put a button inside an email input in a Django form.
This is the code with the button next to the email input:
<div class="container" id="notifyEmailFormContainer">
<form action="{% url "landing:notify_email_add" %}" method="post" id="notifyEmailForm">
{% csrf_token %}
<div class="form-group row">
<div class="col-sm-10 input-group" id="emailInput">
<div class="input-group-addon" id="comingSoonEmailIcon"><i class="fa fa-envelope fa fa-2x" aria-hidden="true"></i></div>
<input class="form-control" type="email" name="email" placeholder="Your email...." maxlength="255" required id="id_email"/>
</div>
<div class="col-sm-2">
<button type="button" class="btn btn-block btn-primary" onclick="addNotifyEmail()" id="submitNotifyEmail">Notify Me</button>
</div>
</div>
</form>
</div>
I have a tried a couple answers in similar questions but it seems I can't get it to work.

Categories