close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Server Validation if Recordset not empty

Thread began 2/21/2012 5:36 pm by toni272059 | Last modified 5/27/2014 10:45 am by Jason Byrnes | 4748 views | 14 replies |

toni272059

Server Validation if Recordset not empty

Working on order form for product_details.php that shows options for Embroidery ONLY for some Products.

I have successfully setup the Select Option to Show if Recordset not empty. So in the case of products that do not offer Embroidery the Select Options are hidden.

Next I added 2 validations, one to select from a list of colors and one to select Embroidery or Plain.

Problem is all Products pass thru the detail_products.php before being Added to Cart. So the page will not validate when there is no selection for Embroidery even though to the customer the option is not available. All they see is the Validation Show if error message and the item is not added to Shopping Cart

I have read various posts about using the
<?php if ($totalRows_rsEmbroidery > 0) { // Show if recordset not empty ?>
and tried putting around WAFV code but result is an error message about an undefined variable.

Follows the php for Form Validation with the added <?php if ($totalRows.....
<?php
if (isset($_POST["eCart1_1_ATC_x"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_productdetail_366_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ(((isset($_POST["eCart1_1_Color_Add"]))?$_POST["eCart1_1_Color_Add"]:"") . "",true,1);
if ($totalRows_rsEmbroidery > 0) {
$WAFV_Errors .= WAValidateRQ(((isset($_POST["eCart1_1_Embroidery_Add"]))?$_POST["eCart1_1_Embroidery_Add"]:"") . "",true,2);
}
if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"productdetail_366");
}
}
?>

And code for Form Select
<?php if ($totalRows_rsEmbroidery > 0) { // Show if recordset not empty ?>
<select name="eCart1_1_Embroidery_Add">
<option value="">Select Embroidery Option</option>
<?php
do {
?>
<option value="<?php echo $row_rsEmbroidery['ProductOptionID']?>"><?php echo $row_rsEmbroidery['OptionName']?></option>
<?php
} while ($row_rsEmbroidery = mysql_fetch_assoc($rsEmbroidery));
$rows = mysql_num_rows($rsEmbroidery);
if($rows > 0) {
mysql_data_seek($rsEmbroidery, 0);
$row_rsEmbroidery = mysql_fetch_assoc($rsEmbroidery);
}
?></select>
<?php } // Show if recordset not empty ?></td>

And code for Validation Show if
<?php
if (ValidatedField('productdetail_366','productdetail_366')) {
if ((strpos((",".ValidatedField("productdetail_366","productdetail_366").","), "," . "2" . ",") !== false || "2" == "")) {
if (!(false)) {
?>
<span style="color: #d73436">Please select an Embroidery Option</span> <br />
<?php //WAFV_Conditional product_detail.php productdetail_366(2:) <-- not a smiley face should be colon and closing bracket.
}
}
}?>

Sign in to reply to this post

Jason ByrnesWebAssist

please send a copy of the page in a zip archive so I can see the code in context.

Sign in to reply to this post

toni272059

product_detail.php zip file attached

includes my attempt at approve validation if no Embroidery option to validate

thanks!

Attached Files
product_detail.php.zip
Sign in to reply to this post

Jason ByrnesWebAssist

the problem is code order.

the code to perform the validation is at lines 14 - 30.

the code that creates the recordset is at lines 31 - 117.

those code blocks need to be switched around so that the recordset exists when the validation tries to use it.

Sign in to reply to this post

toni272059

Perfect. Thank you!

Sign in to reply to this post

Jason ByrnesWebAssist

no worries.

Sign in to reply to this post

toni272059

Continuing the Product Detail page Validation process

I now need to validate the embroidery selection process before the Add to Cart is submitted

I have it working when the Add Embroidery option is selected from the dynamic select menu or embroidery is not offered for the product.

I am stumbling on when embroidery is offered and the No Embroidery option is selected.
Currently the validation process is being activated for those fields

I have the following for when embroidery is not even offered for a product

if ($totalRows_rsEmbroidery > 0) {
$WAFV_Errors .= WAValidateRQ(((isset($_POST["eCart1_1_Embroidery_Add"]))?$_POST["eCart1_1_Embroidery_Add"]:"") . "",true,2);
}

however this is not working for the embroidery selection process fields

if ($totalRows_rsEmbroidery > 0) {
$WAFV_Errors .= WAValidateRQ(((isset($_POST["eCart1_1_EmbroideryType_Add"]))?$_POST["eCart1_1_EmbroideryType_Add"]:"") . "",true,3);
$WAFV_Errors .= WAValidateRQ(((isset($_POST["eCart1_1_embroiderystyle_Add"]))?$_POST["eCart1_1_embroiderystyle_Add"]:"") . "",true,4);
$WAFV_Errors .= WAValidateRQ(((isset($_POST["EmbroideryText"]))?$_POST["EmbroideryText"]:"") . "",true,5);
}

I understand it is not the correct 'if' statement.
What I need to be asking is 'if' the customer selects the second option on the dynamic select menu then continue with the validation process

something similar to
if(optionIndex == '2') {
$WAFV_Errors .= WAValidateRQ .....
}

but needs to be specific to the <select name="eCart1_1_Embroidery_Add"> menu

I have attached the product_detail file

thanks

Attached Files
product_detail.php.zip
Sign in to reply to this post

Jason ByrnesWebAssist

try changing:

php:
if ($totalRows_rsEmbroidery >= 2) {



to:

php:
if (isset($_POST["eCart1_1_Embroidery_Add"]) && $_POST["eCart1_1_Embroidery_Add"] == "2") {
Sign in to reply to this post

toni272059

Thanks, that worked for one group but not the other

There are actually three options for embroidery (select menus show relevant options by product)
-- plain (no embroidery)
-- embroidery with $15 surcharge
-- embroidery with price included in product price

The $15 surcharge OR price included is option #2 in their respective select lists (either way customer has to make embroidery selection). Plain (no embroidery) always being #1

For some reason the $15 surcharge menu item works with the validation
product_detail.php?ProductID=1

The price included does not, validation is ignored.
product_detail.php?ProductID=13

<?php
if (isset($_POST["eCart1_1_ATC_x"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_productdetail_366_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ(((isset($_POST["eCart1_1_Color_Add"]))?$_POST["eCart1_1_Color_Add"]:"") . "",true,1);
if ($totalRows_rsEmbroidery > 0) {
$WAFV_Errors .= WAValidateRQ(((isset($_POST["eCart1_1_Embroidery_Add"]))?$_POST["eCart1_1_Embroidery_Add"]:"") . "",true,2);
}
if (isset($_POST["eCart1_1_Embroidery_Add"]) && $_POST["eCart1_1_Embroidery_Add"] == "2") {
$WAFV_Errors .= WAValidateRQ(((isset($_POST["eCart1_1_EmbroideryType_Add"]))?$_POST["eCart1_1_EmbroideryType_Add"]:"") . "",true,3);
$WAFV_Errors .= WAValidateRQ(((isset($_POST["eCart1_1_embroiderystyle_Add"]))?$_POST["eCart1_1_embroiderystyle_Add"]:"") . "",true,4);
$WAFV_Errors .= WAValidateRQ(((isset($_POST["EmbroideryText"]))?$_POST["EmbroideryText"]:"") . "",true,5);
}
if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"productdetail_366");
}
}
?>

Could it be related to the database table options.Options ID?
Plain is 1
+$15 is 2
Included is 12

I did try changing == "2" to >= "2" but that messed with the Plain #1 option, causing the embroidery selection validation to activate again

Sign in to reply to this post

Jason ByrnesWebAssist

the value of the price included option is 87:
<option value="87">Embroidery (Included)</option>



so this code:

php:
if (isset($_POST["eCart1_1_Embroidery_Add"]) && $_POST["eCart1_1_Embroidery_Add"] == "2") {




could be modified to:

php:
if (isset($_POST["eCart1_1_Embroidery_Add"]) && ($_POST["eCart1_1_Embroidery_Add"] == "2" || $_POST["eCart1_1_Embroidery_Add"] == "87")) {
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...