Reputation: 563
the following input field i have in my form:
<input type="hidden" name="editShapeStatus" id="editShapeStatus" value="keep" />
the user can perform multiple actions which could change the value of the input.
the jquery function to change the value:
$('#editShapeStatus').val("lto");
now it gets funny. althought the form has method="POST" as an attribute, the server receives an GET request. BUT only if the value of editShapeStatus was changed by jQuery. An it gets better:
currently the value can be changed to "lto" and "uls". If i use firebug to change the status manually back to "keep", the server receives a normal POST request. If i change the value to any of the other two manually, the server receives a GET request. Even changing the status names that can be passed to the input as the value will not work. This only results in those two newly named status to cause the same error. interestingly enough, manually changing the value to any other string does work properly. even if i change the status names of "lto" and "uls", those two could be used, but not the new names.
So i thought it must have something to do with jQuery. But the only way i am using it to alter the value i listed above.
any suggestions?
Edit:
the form:
<form role="form" method="POST" action="{{ path('save_border') }}">
<div class="form-group">
<input type="hidden" name="borderId" id="borderId" value="{{ border.id }}" /> {# here it tells the controller that we have an existing border to edit #}
<input type="hidden" name="editShapeStatus" id="editShapeStatus" value="keep" />
<input type="hidden" name="toLink" id="toLink" value="no" />
<input type="hidden" name="shapeId" id="shapeId" value="{{ border.borderShape.id }}" />
</div>
<div class="form-group">
<input class="form-control" type="hidden" name="vertices" id="vertices" required /> {# here the vertices need to be stored #}
</div>
<div class="form-group">
<input class="form-control" type="text" name="countryName" id="countryName" placeholder="Germany" value="{{ border.name }}" required />
</div>
<div class="form-group">
<div class="input-group">
<input class="form-control" type="number" name="year" id="year" placeholder=1868 value="{{ border.year }}" required />
<input type="hidden" name="adbcValueMeta" id="adbcValueMeta" value="{% if border.year < 0 %}bc{% else %}ad{% endif %}" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" id="adbcSwitcherMeta">{% if border.year < 0 %}BC{% else %}AD{% endif %}</button>
</span>
</div>
</div>
<div class="form-group">
<textarea class="form-control" name="description" id="description" placeholder="Description">{{ border.description }}</textarea>
</div>
<div class="form-group">
<button class="btn btn-success pull-right" type="submit" id="submitCountryBorderButton">
<span class="glyphicon glyphicon-ok-sign"></span> Save
</button>
</div>
</form>
function to change the value of #editShapeStatus:
$(document).on('click', '#useShapeForEditing', function() {
$('#editShapeStatus').val("uls");
});
the #userShapeForEditing button gets created dynamically.
Upvotes: 1
Views: 631
Reputation: 563
Symfony returned not quite accurate response when it said it could not find the GET Route. There was acutally a call to a method of an entity that did not exist anymore. How Symfony managed to see that as a problem of routing does escape my knowledge, since the controller referenced by the route was indeed called.
The weird behaviour, which i thought was caused by jquery was actually just the result of the controller, who only executed that said non-existent method when the value in editShapeStatus was correct (if - else). thats why it worked with anything else.
Upvotes: 1
Reputation: 24638
With the jsfiddle you provided, I clicked link
and the value changed as you'll see below. Then I clicked save and a POST
was made ... not a GET
:
Remote Address:162.243.204.190:80
Request URL:http://fiddle.jshell.net/border/save/
Request Method:POST
Status Code:404 NOT FOUND
Request Headersview source
..........
Form Data:
borderId:12
editShapeStatus:uls
toLink:no
shapeId:38
vertices:
countryName:Poland
year:1868
adbcValueMeta:ad
description:blabla
And I also confirmed that a POST
request is made when the value as is: keep
.
Therefore jQuery has nothing to do with the changing of the request method from POST
to GET
. We must look elsewhere!
Upvotes: 0