close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Unique Validation triggers error if field is left blank

Thread began 4/19/2012 8:32 am by Ian S | Last modified 4/20/2012 10:22 am by Ian S | 1370 views | 4 replies |

Ian S

Unique Validation triggers error if field is left blank

Hi,

I am currently putting a page together with a couple of form fields on.

Both fields are required, and the first field needs to be unique.

<?php 
if (isset($_POST["BT_Create"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_pluginnew_788_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ(((isset($_POST["friendlyname"]))?$_POST["friendlyname"]:"") . "",true,1);
$WAFV_Errors .= WAValidateRQ(((isset($_POST["filename"]))?$_POST["filename"]:"") . "",true,2);
$WAFV_Errors .= WAValidateUnique("webcatdb",$webcatdb,$database_webcatdb,"plugins","plugin_id","none,none,NULL","0","plugin_name","',none,''","".(((isset($_POST["friendlyname"]))?$_POST["friendlyname"]:"")) ."",true,3);

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



I then have two error messages next to the friendlyname field. These are wrapped in Show If statements.

<?php
if (ValidatedField('pluginnew_788','pluginnew_788')) {
if ((strpos((",".ValidatedField("pluginnew_788","pluginnew_788").","), "," . "1" . ",") !== false || "1" == "")) {
if (!(false)) {
?>
<span class="texterror">Please enter a friendly name for this plugin.</span>
<?php //WAFV_Conditional pluginnew.php pluginnew_788(1:)
}
}
}?>



<?php
if (ValidatedField('pluginnew_788','pluginnew_788')) {
if ((strpos((",".ValidatedField("pluginnew_788","pluginnew_788").","), "," . "3" . ",") !== false || "3" == "")) {
if (!(false)) {
?>
<span class="texterror">A plugin with this name already exists.
<?php //WAFV_Conditional pluginnew.php pluginnew_788(3:)
}
}
}?>



My problem seems to be that if the friendlyname field is left blank, the Unique validation error triggers and is shown aswell as the required error message.

Is there a way to stop the Unique validation error showing if the field is left blank, and only show the 'required' error?

Cheers
Ian

Sign in to reply to this post

Jason ByrnesWebAssist

It sounds like there is an empty record in the plugin_name column of your database that is triggering the Unique validation to fail if the field is left blank.


the unique validation error will only show if that validation has failed. The required validation wont trigger it to show. so it must be finding a blank value in the database that is triggering it.
make sure there are no blanks in the plugin_name column

Sign in to reply to this post

Ian S

Thanks Jason,

Yes, I did think that but the the table is empty. I have truncated it to make sure.

Very strange!

Sign in to reply to this post

Jason ByrnesWebAssist

hmmm, ok, try changing this line:


php:
if ((strpos((",".ValidatedField("pluginnew_788","pluginnew_788").","), "," . "3" . ",") !== false || "3" == ""))  {




to:

php:
if ((strpos((",".ValidatedField("pluginnew_788","pluginnew_788").","), "," . "3" . ",") !== false || "3" == "") && !(strpos((",".ValidatedField("pluginnew_788","pluginnew_788").","), "," . "1" . ",") !== false || "1" == ""))  {
Sign in to reply to this post

Ian S

Thanks Jason,

Yes, that does get around the problem!

I can work with that for now.

Thanks again.

Ian

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