Restricting the Quantity field to be an integer
I have a very old eCart application (probably started with v3 and has had only minor changes since).
I want to restrict the Quantity field to be an integer only. I know the correct method of doing this with v5 would be to select integer from the eCart object for the Quantity field. However when I do this I get fatal errors elsewhere in the application.
I found an old thread from Jason (http://www.webassist.com/forums/posts.php?id=9892) that recommended doing a coding change in the eCart object. This would be my preferred solution.
Change:-
if (isset($_POST[$this->CartName."_Quantity_".$n])) {
$itemQuantity = floatval($_POST[$this->CartName."_Quantity_".$n]);
}
to:-
if (isset($_POST[$this->CartName."_Quantity_".$n]) && is_int($_POST[$this->CartName."_Quantity_".$n)) {
$itemQuantity = floatval($_POST[$this->CartName."_Quantity_".$n]);
}
However when I try this then DW is reporting a syntax error. However I can't see any reason for the syntax error.
The code where I am making the change is this;-
$itemQuantity = null;
if (isset($_POST[$this->CartName."_Quantity_hid_".$n])) {
$itemQuantity = floatval($_POST[$this->CartName."_Quantity_hid_".$n]);
}
if (isset($_POST[$this->CartName."_Quantity_list_".$n])) {
$itemQuantity = floatval($_POST[$this->CartName."_Quantity_list_".$n]);
}
if (isset($_POST[$this->CartName."_Quantity_".$n])) {
$itemQuantity = floatval($_POST[$this->CartName."_Quantity_".$n]);
}
if (isset($_POST[$this->CartName."_Quantity_check_".$n])) {
$itemQuantity = floatval($_POST[$this->CartName."_Quantity_check_".$n]);
}
Any suggestions would be much appreciated.