Suppose I’m wanting to extract some data from an html form on POST event, NOT in a django form.
In my views.py I can call “request.POST” and I get a dictionary of “name and value”. But in this case the names are all the same.
Is there a way that I can get the “id” instead of the name for example? w/o changing the html in the template ?
Pretty much a rookie here, don’t be too harsh on me
Here’s a snippet of the django template :
<!-- Radio Buttons -->
<div class="form__group">
<div class="form__radio-group">
<input class="form__radio-input" type="radio" id="year1" name="year">
<label class="form__radio-label" for="year1">
<span class="form__radio-button"></span>
1st year
</label>
</div>
<div class="form__radio-group">
<input class="form__radio-input" type="radio" id="year2" name="year">
<label class="form__radio-label" for="year2">
<span class="form__radio-button"></span>
2nd year
</label>
</div>
<div class="form__radio-group">
<input class="form__radio-input" type="radio" id="year3" name="year">
<label class="form__radio-label" for="year3">
<span class="form__radio-button"></span>
3rd year
</label>
</div>
<div class="form__radio-group">
<input class="form__radio-input" type="radio" id="year4" name="year">
<label class="form__radio-label" for="year4">
<span class="form__radio-button"></span>
4th year
</label>
</div>
</div>
For reference, I've solved this by using "value=1", as suggested by WillemVanOnsem in the comments, as such:
<!-- Radio Buttons -->
<div class="form__group">
<div class="form__radio-group">
<input class="form__radio-input" type="radio" id="year1" name="year" value=1>
<label class="form__radio-label" for="year1">
<span class="form__radio-button"></span>
1st year
</label>
</div>
<div class="form__radio-group">
<input class="form__radio-input" type="radio" id="year2" name="year" value=2>
<label class="form__radio-label" for="year2">
<span class="form__radio-button"></span>
2nd year
</label>
</div>
<div class="form__radio-group">
<input class="form__radio-input" type="radio" id="year3" name="year" value=3>
<label class="form__radio-label" for="year3">
<span class="form__radio-button"></span>
3rd year
</label>
</div>
<div class="form__radio-group">
<input class="form__radio-input" type="radio" id="year4" name="year" value=4>
<label class="form__radio-label" for="year4">
<span class="form__radio-button"></span>
4th year
</label>
</div>
</div>
The POST request sends out the value (ie: 1 for year 1), which is what I wanted to accomplish!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments