The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.27 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.27 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/printthread.php 16 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.27 (Linux)
File Line Function
/global.php 909 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1370 fetch_forum_permissions
/printthread.php 76 forum_permissions
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.27 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.27 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.27 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.27 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.27 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.27 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.27 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.27 (Linux)
File Line Function
/printthread.php 165 errorHandler->error



Form Tools
Unique fields - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1)
+--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5)
+--- Thread: Unique fields (/showthread.php?tid=1321)



Unique fields - floppyraid - May 22nd, 2011

Greetings,

I am really digging this, thank you all who were involved in creating it.

I have a (hopefully) quick question. I'm trying to set up an extremely basic inventory tracking log of sorts. I have some fields (columns in tables) that need to have a check for uniqueness. Is this best done in PHP or in an SQL DISTINCT query or by manually forcing a column to have all unique identifiers?

I would like to have an indication (not a generic mysql error) that the entry is not unique and is a duplicate for the end user on their browser when attempting to enter it in through a field.

So far everything is working great in terms of the forms posting their data into the SQL table, but I do not see anything in the options of Form Tools to have a check for unique data.

Again, mad props to all involved in the development of this. I was trying to recreate this very thing by hand for the last 2 days before I discovered Form Tools quite by mistake.


RE: Unique fields - Ben - May 22nd, 2011

Hi Floppyraid,

Thanks for the kind words!

Regarding your problem, there's nothing within the Form Tools Core that let's you check for uniqueness, but its been a common request so I added it to the API. Check out this page:
http://docs.formtools.org/api/?page=ft_api_check_submission_is_unique

The only drawback is that you have to use the API (i.e. PHP) to submit the code to the Form Tools script, instead of just POST-ing it to it. Here's a couple of tutorials on how to do it, depending on your situation:
http://docs.formtools.org/tutorials/api_single_page_form/
http://docs.formtools.org/tutorials/api_multi_page_form/

Good luck! Smile

- Ben


RE: Unique fields - floppyraid - May 22nd, 2011

Greetings again,

I cannot seem to get this thing going. I am hoping that I am overlooking something extremely simple. This is what I have as of right now.

Code:
<?php
require_once("formtools/global/api/api.php");
$fields = ft_api_init_form_page(2);
include 'header.php';

$criteria = array(
  "col_2" => $_POST["col_2"]
);
if (!ft_api_check_submission_is_unique(2, $criteria))
{
  $already_exists = true;
}
else
{
$params = array(
  "submit_button" => "czech",
  "next_page" => "madprops.php",
  "form_data" => $_POST,
  "finalize" => true
    );
ft_api_process_form($params);
}
?>
<html><body><form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
Monitor ID: <input type="text" name="monitor_id">
Unit ID: <input type="text" name="unit_id">
<select name="location" size="1">
<?php
mysql_connect($sqlsrv,$username,$password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
$query = "SELECT DISTINCT location FROM inventory.inventory";
$result = mysql_query($query);
if(mysql_num_rows($result)) {
while($row = mysql_fetch_row($result))
{ print("<option value=\"$row[0]\">$row[0]</option>"); }
} else { print("<option value=\"\">NO LOCATIONS?!</option>"); }
?>
</select>
<input type="hidden" name="returned" value="N">
<input type="submit" name="czech">
</center></div></form></body></html>

As it is now, the data is always added to the table regardless of wither or not the information provided destined for col_2 is unique (col_2 is what the column is named for the unit id's)

Sorry, I've tried several ways and read and reread. I am a bit confused by what is mentioned on the page: http://docs.formtools.org/api/?page=ft_api_check_submission_is_unique

at the top it says
Code:
ft_api_check_submission_is_unique($form_id, $criteria, $submission_id]);
but a little further down it provides the example as:
Code:
if (!ft_api_check_submission_is_unique(10, $criteria, $fields["form_tools_submission_id"]))

perhaps i am overlooking something very basic (i am by no means proficient in php)

if anyone wants to sorta nudge me in the right direction i would be extremely greatful


-----

EDIT:

sorry, figured it out.

http://docs.formtools.org/tutorials/checking_for_uniqueness/?page=uniqueness_check

the bottom of the page explains in a little more detail what i needed to know to figure out how i was in error. i didnt see it linked anywhere on the site but a google search of ft_api_check_submission_is_unique picked it up


RE: Unique fields - Ben - May 27th, 2011

Ah, good to hear! Sorry the page wasn't too clear.

- Ben