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
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
Keeping values in fields with ft_api_check_submission_is_unique - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1)
+--- Forum: API (https://forums.formtools.org/forumdisplay.php?fid=17)
+--- Thread: Keeping values in fields with ft_api_check_submission_is_unique (/showthread.php?tid=315)



Keeping values in fields with ft_api_check_submission_is_unique - msaz87 - Sep 30th, 2009

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/turkey_bowl/register_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!


RE: Keeping values in fields with ft_api_check_submission_is_unique - msaz87 - Oct 2nd, 2009

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.


RE: Keeping values in fields with ft_api_check_submission_is_unique - Ben - Oct 29th, 2009

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


RE: Keeping values in fields with ft_api_check_submission_is_unique - msaz87 - Oct 30th, 2009

(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!

[attachment=35][attachment=34]


RE: Keeping values in fields with ft_api_check_submission_is_unique - PTTW - Dec 16th, 2009

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!!!


RE: Keeping values in fields with ft_api_check_submission_is_unique - msaz87 - Dec 16th, 2009

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