J'essaie de vérifier que certains champs de mon formulaire sont numériques et non textuels. Où commencerais-je?jquery valider avant de sérialiser
Si les champs sont numériques, effectuez une sérialisation, sinon envoyez une chaîne vide. La raison pour laquelle je veux faire ceci est parce que PHP voit les données pour chaque variable comme une chaîne et non numérique.
ceci est ma demande ajax
$.ajax({
type: "POST",
url: "lib/calc.php",
data: $("#calcQuery").serialize(),
dataType: "html",
success: function(response)
{
$("#calcBox").html(response);
$("#calcBox").show();
clearForm("#calcQuery");
},
c'est ma forme
<form id="calcQuery" class="ui-widget-shadow ui-corner-all" style="margin-top: 1em;">
<fieldset class="ui-corner-all" >
<table border="0" width="85%">
<tr>
<th><nobr><label for="curr_alloc">Current Space Allocation:</label></nobr></th>
<td align="right"><input type="text" size="5" name="curr_alloc" id="curr_alloc" /></td>
</tr>
<tr>
<td>
<table border="0" style="margin-left: .5em;">
<tr>
<td>
<input type="radio" name="curr_unit" value="KB" /><label>KB</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="curr_unit" value="MB" /><label>MB</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="curr_unit" value="GB" checked /><label>GB</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="curr_unit" value="TB" /><label>TB</label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<th><nobr><label for="curr_percent">Current Usage Percentage:</label></nobr></th>
<td align="right"><input type="text" size="5" name="curr_percent" id="curr_percent" /></td>
</tr>
<tr>
<th><nobr><label for="desired_percent">Desired Usage Percentage:</label></nobr></th>
<td align="right"><input type="text" size="5" name="desired_percent" id="desired_percent" /></td>
</tr>
</table>
</fieldset>
</form>
Alors, comment puis-je vérifier que je reçois un certain nombre en PHP si elle ne voit que comme un string ? –
@SimplySeth vous devez le lancer/analyser. Je vais mettre à jour la réponse. –