close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Please help - can't figure out how to stop insert record on form validation

Thread began 9/01/2010 11:51 am by dan361748 | Last modified 9/01/2010 4:31 pm by Jason Byrnes | 681 views | 3 replies |

dan361748

Please help - can't figure out how to stop insert record on form validation

Hi - can't figure out what I am doing wrong.

Trying to stop duplicate records from being inserted into my table, using 'email' as the key.

I have set up my recordset to check the email, created the form have the validation show if behaviour showing the error if there is a duplicate record.

Even if the error shows, the insert record still puts the record in.

I have been trying using the Rules manager to create a rule that is success if $totalRows_usremails is null (I think?) but just can't seem to figure it out. I then set the insert record behaviour to trigger on Rule: Validation Success but either get header errors or it doesn't work.

Please help! My error messages work but the insert record ignores them!

Sign in to reply to this post

Jason ByrnesWebAssist

you need to use the Server Validations part of CSS Form Buiilder.

Go to Insert -> Webassist -> CSS Form Builder -> Server Validations


Select number validation.

For the server variable enter:
$totalRows_RecordsetName

where RecordsetName is the name of your recordset.

Set the minimum to -1 and the max to 0

Sign in to reply to this post

dan361748

Thanks Jason - I've done this but it still does not work.

I've removed all my 'validate show if' to make the code a little simpler. At this point, I just want the form to not insert a record if the validation fails, which I can't seem to do.

$totalRows_usremails is returning a value larger than 0, but the form still posts to the table. Can you help further?

<?php
ERROR_REPORTING(E_ALL);
ini_set("display_errors","ON");
?>
<?php require_once('Connections/boomcms.php'); ?>
<?php require_once("WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php require_once("WA_ValidationToolkit/WAVT_Scripts_PHP.php"); ?>
<?php require_once("WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$colname_usremails = "-1";
if (isset($_POST['email'])) {
$colname_usremails = (get_magic_quotes_gpc()) ? $_POST['email'] : addslashes($_POST['email']);
}
mysql_select_db($database_boomcms, $boomcms);
$query_usremails = sprintf("SELECT * FROM newssubscribe WHERE email = %s", GetSQLValueString($colname_usremails, "text"));
$usremails = mysql_query($query_usremails, $boomcms) or die(mysql_error());
$row_usremails = mysql_fetch_assoc($usremails);
$totalRows_usremails = mysql_num_rows($usremails);
?>
<?php
// WA Application Builder Insert
if ($_SERVER["REQUEST_METHOD"] == "POST") // Trigger
{
$WA_connection = $boomcms;
$WA_table = "newssubscribe";
$WA_sessionName = "newssubscribe_id";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "newssubscribe_id";
$WA_fieldNamesStr = "firstname|lastname|email|postzip|subscribelive";
$WA_fieldValuesStr = "".((isset($_POST["firstname"]))?$_POST["firstname"]:"") ."" . "|" . "".((isset($_POST["lastname"]))?$_POST["lastname"]:"") ."" . "|" . "".((isset($_POST["email"]))?$_POST["email"]:"") ."" . "|" . "".trim(strtoupper(((isset($_POST["postzip"]))?$_POST["postzip"]:""))) ."" . "|" . "1";
$WA_columnTypesStr = "',none,''|',none,''|',none,''|',none,''|none,none,NULL";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_boomcms;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$WAFV_Redirect = "";
$_SESSION['WAVT_subscribe_393_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateNM($totalRows_usremails . "",-1,0,"",",.",true,1);

if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"subscribe_393");
}
}
?>

Sign in to reply to this post

Jason ByrnesWebAssist

thje problem is code order, the validation is happening after the record inserts.


change:

php:
<?php

// WA Application Builder Insert
if ($_SERVER["REQUEST_METHOD"] == "POST"// Trigger
{
$WA_connection $boomcms;
$WA_table "newssubscribe";
$WA_sessionName "newssubscribe_id";
$WA_redirectURL "";
$WA_keepQueryString false;
$WA_indexField "newssubscribe_id";
$WA_fieldNamesStr "firstname|lastname|email|postzip|subscribeliv e";
$WA_fieldValuesStr "".((isset($_POST["firstname"]))?$_POST["firstname"]:"") ."" "|" "".((isset($_POST["lastname"]))?$_POST["lastname"]:"") ."" "|" "".((isset($_POST["email"]))?$_POST["email"]:"") ."" "|" "".trim(strtoupper(((isset($_POST["postzip"]))?$_POST["postzip"]:""))) ."" "|" "1";
$WA_columnTypesStr "',none,''|',none,''|',none,''|',none,''|none,none ,NULL";
$WA_fieldNames explode("|"$WA_fieldNamesStr);
$WA_fieldValues explode("|"$WA_fieldValuesStr);
$WA_columns explode("|"$WA_columnTypesStr);
$WA_connectionDB $database_boomcms;
mysql_select_db($WA_connectionDB$WA_connection);
if (!
session_id()) session_start();
$insertParamsObj WA_AB_generateInsertParams($WA_fieldNames$WA_columns$WA_fieldValues, -1);
$WA_Sql "INSERT INTO `" $WA_table "` (" $insertParamsObj->WA_tableValues ") VALUES (" $insertParamsObj->WA_dbValues ")";
$MM_editCmd mysql_query($WA_Sql$WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if (
$WA_redirectURL != "") {
if (
$WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL'?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$WAFV_Redirect "";
$_SESSION['WAVT_subscribe_393_Errors'] = "";
if (
$WAFV_Redirect == "") {
$WAFV_Redirect $_SERVER["PHP_SELF"];
}
$WAFV_Errors "";
$WAFV_Errors .= WAValidateNM($totalRows_usremails "",-1,0,"",",.",true,1);

if (
$WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"subscribe_ 393");
}
}
?>





to:

php:
<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$WAFV_Redirect "";
$_SESSION['WAVT_subscribe_393_Errors'] = "";
if (
$WAFV_Redirect == "") {
$WAFV_Redirect $_SERVER["PHP_SELF"];
}
$WAFV_Errors "";
$WAFV_Errors .= WAValidateNM($totalRows_usremails "",-1,0,"",",.",true,1);

if (
$WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"subscribe_ 393");
}
}
?>
<?php
// WA Application Builder Insert
if ($_SERVER["REQUEST_METHOD"] == "POST"// Trigger
{
$WA_connection $boomcms;
$WA_table "newssubscribe";
$WA_sessionName "newssubscribe_id";
$WA_redirectURL "";
$WA_keepQueryString false;
$WA_indexField "newssubscribe_id";
$WA_fieldNamesStr "firstname|lastname|email|postzip|subscribeliv e";
$WA_fieldValuesStr "".((isset($_POST["firstname"]))?$_POST["firstname"]:"") ."" "|" "".((isset($_POST["lastname"]))?$_POST["lastname"]:"") ."" "|" "".((isset($_POST["email"]))?$_POST["email"]:"") ."" "|" "".trim(strtoupper(((isset($_POST["postzip"]))?$_POST["postzip"]:""))) ."" "|" "1";
$WA_columnTypesStr "',none,''|',none,''|',none,''|',none,''|none,none ,NULL";
$WA_fieldNames explode("|"$WA_fieldNamesStr);
$WA_fieldValues explode("|"$WA_fieldValuesStr);
$WA_columns explode("|"$WA_columnTypesStr);
$WA_connectionDB $database_boomcms;
mysql_select_db($WA_connectionDB$WA_connection);
if (!
session_id()) session_start();
$insertParamsObj WA_AB_generateInsertParams($WA_fieldNames$WA_columns$WA_fieldValues, -1);
$WA_Sql "INSERT INTO `" $WA_table "` (" $insertParamsObj->WA_tableValues ") VALUES (" $insertParamsObj->WA_dbValues ")";
$MM_editCmd mysql_query($WA_Sql$WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if (
$WA_redirectURL != "") {
if (
$WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL'?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>




so that the validation will occur before inserting the form

Sign in to reply to this post

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...