Sep 5th, 2009, 11:25 PM
Hey Ben,
I updated the API files and also my code, which now looks like this, in full:
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!
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>
<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!