FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unique fields
#1
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.
Reply
#2
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_a..._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_...page_form/
http://docs.formtools.org/tutorials/api_...page_form/

Good luck! Smile

- Ben
Reply
#3
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_a..._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/chec...ness_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
Reply
#4
Ah, good to hear! Sorry the page wasn't too clear.

- Ben
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)