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
Keeping values in fields with ft_api_check_submission_is_unique
#1
I've been working to combine validation along with ft_api_check_submission_is_unique and while it all works -- the values no longer stay in the fields on an error submission. If you remove the ft_api_check_submission_is_unique portion, it works fine.

EDIT: I had to adjust the live example link...
Here's the live example: http://fasports.com/az/phx/tournaments/t...r_TEST.php

And here's the code...

PHP Code:
    require_once("[PATH TO]/global/api/api.php");
    
    if(
$ft_initialize == "yes") { $fields ft_api_init_form_page($ft_id"initialize"); }
    else { 
$fields ft_api_init_form_page($ft_id); }
    
    
// $fields = ft_api_init_form_page($ft_id); // placeholder as it's defined above

    
$already_exists "";
    
    
// validation time!
    
$errors = array();
    if (isset(
$_POST['submit']))
    {
      
$rules = array();

      
$rules[] = "required,Team_Name,Please enter your team name.";
      
$rules[] = "required,Email_Address,Please enter your email address.";
      
$rules[] = "required,Captains_First_Name,Please enter your captain's first name.";
      
$rules[] = "required,Captains_Last_Name,Please enter your captain's last name.";
      
$rules[] = "required,Phone_Number,Please enter your phone number.";
      
$rules[] = "required,Terms_and_Conditions,Please confirm you have read and agree to the terms and conditions.";
      
      
$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" => "reg_confirm_new.php",
          
"form_data" => $_POST,
          
"finalize" => true
        
);        

    
    
 
$criteria = array(
  
"col_2" => $_POST["Team_Name"]
);
if (!
ft_api_check_submission_is_unique($ft_id$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);
  
  
}  } } } 

And the code for the same thing but without the ft_api_check_submission_is_unique:

PHP Code:
    require_once("[PATH TO]/manager/registration/global/api/api.php");
    
    if(
$ft_initialize == "yes") { $fields ft_api_init_form_page($ft_id"initialize"); }
    else { 
$fields ft_api_init_form_page($ft_id); }
    
    
// $fields = ft_api_init_form_page($ft_id); // placeholder as it's defined above

    
$already_exists "";
    
    
// validation time!
    
$errors = array();
    if (isset(
$_POST['submit']))
    {
      
$rules = array();

      
$rules[] = "required,Team_Name,Please enter your team name.";
      
$rules[] = "required,Email_Address,Please enter your email address.";
      
$rules[] = "required,Captains_First_Name,Please enter your captain's first name.";
      
$rules[] = "required,Captains_Last_Name,Please enter your captain's last name.";
      
$rules[] = "required,Phone_Number,Please enter your phone number.";
      
$rules[] = "required,Terms_and_Conditions,Please confirm you have read and agree to the terms and conditions.";
      
      
$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" => "reg_confirm_new.php",
          
"form_data" => $_POST,
          
"finalize" => true
        
);
        
        
ft_api_process_form($params);
        
        
$fields array_merge($fields$_SESSION["form_tools_form"]);
    }
    else
    
$fields array_merge($fields$_POST);         
        
      } 

I'm assuming there's some portion of code missing that's not relaying the values in an errored submission... but I just have no idea what that might be.

Thanks!
Reply
#2
I adjusted the code a little and I think I made a little progress... by adding in the following two snippets:

PHP Code:
        $fields array_merge($fields$_SESSION["form_tools_form"]); 

PHP Code:
      $fields array_merge($fields$_POST); 

Into the code as shown here:

PHP Code:
      // 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" => "reg_confirm_new.php",
          
"form_data" => $_POST,
          
"finalize" => true
        
);        
    
    
     
$criteria = array(
      
"col_2" => $_POST["Team_Name"]
    );
    if (!
ft_api_check_submission_is_unique($ft_id$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;
      
$fields array_merge($fields$_POST); 
      
    }
    else
    {
      
// call ft_api_process_form function here to continue processing the form submission
        
ft_api_process_form($params);
        
$fields array_merge($fields$_SESSION["form_tools_form"]);
  
}  } } } 

Now when running tests, if you error during validation, the fields don't maintain their values -- but if you only error on the name's uniqueness, they do keep their values.
Reply
#3
Hey msaz,

Sorry for not replying sooner - I've had a pretty busy week! Would you mind posting your entire code? I'd like to see the whole shebang to see if I can spot anything out of whack.

Thanks!

- Ben
Reply
#4
(Oct 29th, 2009, 7:54 PM)Ben Wrote: Hey msaz,

Sorry for not replying sooner - I've had a pretty busy week! Would you mind posting your entire code? I'd like to see the whole shebang to see if I can spot anything out of whack.

Thanks!

- Ben

Sure thing -- thanks so much for helping me.

Attached below are the two files involved (I think, its been a little while since I was working on this, so if it seems like anything is missing just let me know...)

Both are included into other pages which define whether the form needs to be initialized and what ID it is... but everything else should be there. The reg_api.php file contains versions of both the working code w/out the ft_api_check_submission_is_unique and the version not working with it (one is listed as "league registration" and the other "tournament registration").

And on the confirm page, of course, is the:

PHP Code:
require_once("[PATH TO]/global/api/api.php");
$fields ft_api_init_form_page();
ft_api_clear_form_sessions(); 

That should be all of it..

Thanks again!


.php   tournament_registration_new.php (Size: 7.25 KB / Downloads: 7)
.php   reg_api.php (Size: 3.7 KB / Downloads: 6)
Reply
#5
I did experience this type of issue also.... I changed this:

$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))
{
$fields = ft_api_init_form_page(1);
$params = array(
"submit_button" => "continue",
"next_page" => "step2.php",
"form_data" => $_POST,
"file_data" => $_FILES
);

$criteria = array(
"attendee_last_name" => $_POST["attendee_last_name"],
"attendee_zip" => $_POST["attendee_zip"],
"attendee_email" => $_POST["attendee_email"],
"is_finalized" => "yes",
"status" => "Active"
);

if (!ft_api_check_submission_is_unique(1, $criteria, $files["form_tools_submission_id"]))
{
$already_exists = true;
}
else
{
ft_api_process_form($params);
}
}
}

?>


to this:

$errors = validate_fields($_POST, $rules);

}

if (empty($errors))
{
$fields = ft_api_init_form_page(1);
$params = array(
"submit_button" => "continue",
"next_page" => "step2.php",
"form_data" => $_POST,
"file_data" => $_FILES
);

$criteria = array(
"attendee_last_name" => $_POST["attendee_last_name"],
"attendee_zip" => $_POST["attendee_zip"],
"attendee_email" => $_POST["attendee_email"],
"is_finalized" => "yes",
"status" => "Active"
);

if (!ft_api_check_submission_is_unique(1, $criteria, $files["form_tools_submission_id"]))
{
$already_exists = true;
}
else
{
ft_api_process_form($params);
}
}


?>

and the problem was resolved!!!
Reply
#6
Can you point out exactly what you did differently? Or post more of the code? I'm trying to compare your examples and the only thing I can identify is an orphan end bracket underneath where you declare the $errors variable.

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)