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
SQL error when using ft_api_check_submission_is_unique
#11
Hey Ben,

I updated the API files and also my code, which now looks like this, in full:

PHP Code:
<?php
require_once("../[path to FT]/global/api/api.php");
$fields ft_api_init_form_page(28);

$already_exists "";

// validation time!
$errors = array();
if (isset(
$_POST['submit']))
{
  
$rules = array();
  
$rules[] = "required,how_they_heard_about_us,Please select a referral source.";
  
$rules[] = "required,email,Please enter your email address.";
  
$errors validate_fields($_POST$rules);
 
  
// no errors - great! Now we process the page. The ft_api_process_form does
  // the job of both updating the database and redirecting to the next page
  
if (empty($errors))
  {
    
$params = array(
      
"submit_button" => "submit",
      
"next_page" => "thanks.php",
      
"form_data" => $_POST,
      
"finalize" => true
    
);
    
    
$criteria = array(
  
"col_1" => $_POST["email"]
);
if (
ft_api_check_submission_is_unique(28$criteria$fields["form_tools_submission_id"]))
{    
  
// uh-oh! A submission already exists with this email address! Abort, abort! 
  // here, you could do something like set a variable like: $already_exists = true
  // and in the webpage do a little test to see if it's set. If so, let the user know 
  // what's going on
  
  
$already_exists true;
  
}
else
{
  
// call ft_api_process_form function here to continue processing the form submission
    
ft_api_process_form($params);
  
  
}





  }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>


<head>
</head>
<body>

<? if($already_exists == true) { echo("**This email already exists**<br/><br/>"); } ?>

<?php
// if $errors is not empty, the form must have failed one or more validation 
// tests. Loop through each and display them on the page for the user
if (!empty($errors))
{
  echo 
"<div class='error'>Please fix the following errors:\n<ul>";
  foreach (
$errors as $error)
    echo 
"<li>$error</li>\n";
 
  echo 
"</ul></div>"
}
?>


Join our mailing list for league and tournament updates:
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">

    <input type="text" name="email" size="30">
    <select name="how_they_heard_about_us">
        <option value="">Your Referral Source</option>
        <option value="MySpace">MySpace</option>
        <option value="Facebook">Facebook</option>
        <option value="Search Engine">Search Engine</option>
        <option value="Friend">Friend</option>
        <option value="Advertisement">Advertisement</option>
        <option value="Other">Other</option>
    </select>&nbsp;
    <input type="submit" name="submit" value="submit">

</form>

</body>
</html> 

But I still get the same problem regarding it always coming back telling me the submission isn't unique.

Did I do something wrong?

Thanks so much for your help with this, Ben!
Reply
#12
I also updated to the new version of thr API and same result in a simple test....not unique message when it is.
Reply
#13
Hey azparrothead,

Hmm! Would it be possible for you to send me your PHP page? I'd like to test it out myself (ben.keen@gmail.com).

Thanks!

- Ben
Reply
#14
Just to recap on this thread the solution for anyone else who might run into the problem... via Ben and azparrothead...

The code line involving the IF needs the addition of a "!" before the ft_api_check_submission_is_unique:
PHP Code:
if (!ft_api_check_submission_is_unique(1$criteria$files["form_tools_submission_id"]))
{
$already_exists true;
}
else
{
ft_api_process_form($params);

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)