Jan 13th, 2012, 1:11 PM
(This post was last modified: Jan 13th, 2012, 1:13 PM by michatmaster7.)
Yeesh is right. Ok, I understand the changes to ft_api_init_form_page() and ft_api_clear_form_sessions().
I don't understand PHP enough to know what you mean for the ft_api_process_form() function.
Also - you said: "Each form will need to pass the same unique namespace to every API function."
Does that mean EVERY function on the page? I have more functions than the few you've listed. For error reporting, etc. Nothing custom or complex, though. Do I need to append each of these other functions with a namespace, as well? If so, what would the namespace look like? Here is an example of the PHP header code for one of my forms (I've stripped personal info):
Then my form tag:
My error display snippet:
And lastly, the refilling php for all of the fields, such as:
For this example, I also have the following PHP header code on the respective thank you page:
Also - I just noticed that I'm using the wrong formtools path for the require_once on the thank you page. The form uses the path for installation #2 and the thank you page uses the path from installation #1. That could be a problem, I guess...lol. I'll fix that right now.
Last question (might sound dumb):
Would it be possible to include a ft_api_clear_form_sessions(); on the actual form page itself? Perhaps above where the $fields = ft_api_init_form_page(); line is?
If so, we could clear ALL sessions on page load, before attempting to start a session.... and that would be much simpler than this namespacing thing.
I don't understand PHP enough to know what you mean for the ft_api_process_form() function.
Also - you said: "Each form will need to pass the same unique namespace to every API function."
Does that mean EVERY function on the page? I have more functions than the few you've listed. For error reporting, etc. Nothing custom or complex, though. Do I need to append each of these other functions with a namespace, as well? If so, what would the namespace look like? Here is an example of the PHP header code for one of my forms (I've stripped personal info):
PHP Code:
<?php
require_once("../formtools-path/global/api/api.php");
$fields = ft_api_init_form_page(10);
$errors = array();
if (isset($_POST['submit']))
{
$rules = array();
$rules[] = "required,first_name,Please enter your FIRST NAME.";
// Many more validation lines here, but stripped for this example
$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", // Change to name of submit button
"next_page" => "https://www.domain.com/directory/thanks.php",
"form_data" => $_POST,
"finalize" => true
);
ft_api_process_form($params);
}
// it failed validation. Update $fields with the latest contents of the form data
else
{
$fields = array_merge($_SESSION["form_tools_form"], $_POST);
}
}
?>
Then my form tag:
PHP Code:
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post">
My error display snippet:
PHP Code:
<?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>";
}
?>
And lastly, the refilling php for all of the fields, such as:
PHP Code:
<input name="first_name" size="50" type="text" value="<?=htmlspecialchars(@$fields["first_name"])?>" />
For this example, I also have the following PHP header code on the respective thank you page:
PHP Code:
<?php
require_once("../formtools-path/global/api/api.php");
$fields = ft_api_init_form_page(10);
ft_api_clear_form_sessions();
?>
Also - I just noticed that I'm using the wrong formtools path for the require_once on the thank you page. The form uses the path for installation #2 and the thank you page uses the path from installation #1. That could be a problem, I guess...lol. I'll fix that right now.
Last question (might sound dumb):
Would it be possible to include a ft_api_clear_form_sessions(); on the actual form page itself? Perhaps above where the $fields = ft_api_init_form_page(); line is?
If so, we could clear ALL sessions on page load, before attempting to start a session.... and that would be much simpler than this namespacing thing.