Jun 1st, 2010, 8:37 PM
Hi jaqy,
Neat idea! Yes, this is very doable. Here's how it would work.
You'd add your form normally - it can be either a POST form or an API form - either is fine. But using the API is probably better. If you use the API you can choose whether or not the submissions show up in the Form Tools user interface by explicitly marking them as "finalized". Only finalized submissions show up. POST form submissions are finalized by default, so there's no choice: they'll always appear in the user interface. However, we can hide them with a little trickery.
But the API approach is better, so I'll explain that one.
1. Add your form using the API. For the test submission, follow all the instructions in the tutorials and documentation and add the "finalize" => true option on the final step. Once the form is added, REMOVE that key-value pair. Now, all submissions will be added to the database but won't show up.
2. Add a new field to your form called "unique_key". We're going to populate that value with a random string for all new submissions using the Submission Pre-Parser module. I've documented this pretty well in this tutorial - see steps 2 and 3:
http://docs.formtools.org/tutorials/post...page=step2
It's exactly the same thing, just re-purposed for your case.
3. Now, when you put through new submissions (a) they won't show up but (b) they WILL have a random string generated for each. We're going to use that random string to
Create an email template for your form. This will contain the link to approve the submission (make it show up). In the email content, just use the placeholders that are listed on the page to construct the string. It would look something like this:
http://www.yoursite.com/finalize.php?id=..._uniquekey}
On your site you'll need to create a page called finalize.php containing the following code:
And that's pretty much it. Now, when users click on the link, they'll be taken to that page which parses out the values in the query string and finalizes the submission (if the info is valid).
Neat idea! Yes, this is very doable. Here's how it would work.
You'd add your form normally - it can be either a POST form or an API form - either is fine. But using the API is probably better. If you use the API you can choose whether or not the submissions show up in the Form Tools user interface by explicitly marking them as "finalized". Only finalized submissions show up. POST form submissions are finalized by default, so there's no choice: they'll always appear in the user interface. However, we can hide them with a little trickery.
But the API approach is better, so I'll explain that one.
1. Add your form using the API. For the test submission, follow all the instructions in the tutorials and documentation and add the "finalize" => true option on the final step. Once the form is added, REMOVE that key-value pair. Now, all submissions will be added to the database but won't show up.
2. Add a new field to your form called "unique_key". We're going to populate that value with a random string for all new submissions using the Submission Pre-Parser module. I've documented this pretty well in this tutorial - see steps 2 and 3:
http://docs.formtools.org/tutorials/post...page=step2
It's exactly the same thing, just re-purposed for your case.
3. Now, when you put through new submissions (a) they won't show up but (b) they WILL have a random string generated for each. We're going to use that random string to
Create an email template for your form. This will contain the link to approve the submission (make it show up). In the email content, just use the placeholders that are listed on the page to construct the string. It would look something like this:
http://www.yoursite.com/finalize.php?id=..._uniquekey}
On your site you'll need to create a page called finalize.php containing the following code:
Code:
<?php
require_once("/path/to/api.php");
if (empty($_GET["id"]) || empty($_GET["key"]))
{
header("location: /"); // redirect somewhere...
exit;
}
// here you'll need to replace X with your form ID
$submission_info = ft_api_get_submission(X, $_GET["id"]);
// if the key matches for this submission, finalize it!
if ($submission_info["unique_key"] == $_GET["key"])
{
// replace X here too
ft_finalize_submission(X, $_GET["id"]);
// here you could just redirect to a page that tells the submission
// has been approved. Alternatively you could show it below
header("location: approved.php");
exit;
}
?>
And that's pretty much it. Now, when users click on the link, they'll be taken to that page which parses out the values in the query string and finalizes the submission (if the info is valid).