Hopefully the code makes sense, but heres a few things that might be relevent - if you need these line numbers I suggest you post the code into notepad++, or a program of your choice!
Using url values:
I have the values for 'class' and 'demand' to drive differing text and queries, depending on how the form is launched. So how do they get 'found' ?
Well heres an example URL link (the example is on more than one line just to make it readable here):
http://www.enigmaguild.org/index.php
?option=com_chronocontact
&chronoformname=application_form
&archetype=Soldier
&class=Conqueror
&demand=Medium
&class=Conqueror is the relevent bit.
By placing <?php echo $_GET["class"]?> within my form, I return 'Conqueror' as the value to the form.
if you look at the intro to my form, line 40, you will see a simple example of including this result in a form.
Using a value to pick specific content:
So we can include a value, but what if the content elsewhere in the form is to change, based on this value ?
well look at this section: (lines 43-57)
<?php
switch ($_GET["demand"]) {
case 'High':
echo " <font color=\"#00CC00\"><b>high</b></font>.</p><p>This means that we have launched a priority recruiting drive for your class! If after 48 hours you have heard nothing further, then please contact one of our officers in game to check on the status of your application.";
break;
case "Medium":
echo " <font color=\"#FFCC00\"><b>medium</b></font>.</p><p>This means that we are recruiting at least 3 applicants for your class. If after 5 days you have heard nothing further, then please contact one of our officers in game to check the status of your application.";
break;
case "Low":
echo " <font color=\"#FF6600\"><b>low</b></font>.</p><p>This means that we are only looking for one or two, probably exceptional applicants! Please give us 7 days to review your application. If you are not accepted at this time, we may keep your application on file, for review when the application status changes for your class.";
break;
default:
echo " <font color=\"#ff0000\"><b>closed</b></font>.</p><p>Therefore you are very unlikely to hear anything back from us. However your application will be left in our database, and we do check the database for people to talk-to before reopening recruitment for a given class.";
}
?>
Here we use a case statement, set to the result of the 'get'. So depending on the value, we can display en entirely differing piece of text. However thats just a simple example, later on in the form (lines 320 to 465) the questions being asked change, as a result of a 12 way 'case', however the principle is the same! In the above example also note the use of 'default', a responce given if the case statement is not 'met' - i.e there is no url value for the 'get' to find.
The HTML template - Hidden fields:The HTML template also has a couple of quirks, note that we do not ask for class, (after all we know this form the URL and the 'get' statement), but we still want to use the value for class in the email.
As such we need to include it in the form, as a hidden input, so that we can use {class} in the template. This is done on line 26, and again on line 27 for 'demand'.
Customised Subject Lines:Now we get a bit more interesting. When you fill a form in it gets emailed to you, and to the guild officers with a subject line 'Application from {character_name}, a level {level} {class}' or as an example, 'application from Goldilocks, a level 65 Assassin'.
To achive this we do the following.
Create a hidden field on the form called 'subject' with no value (line 28)
Put this code:
<?php $_POST['subject'] = "Application from " .$_POST['character_name']. " a level " .$_POST['character_level']. " " .$_POST['class']?>
In the onsubmit before sending email
Put the value 'subject' in the subject field, under special fields, in form managment.
In effect what happens is the php code sets the value of the hidden field 'subject' with the content of php string in the form. Note how class has already been set as a value in the form, and the other questions are asked directly.
The special fields use of the value 'subject' takes the content of field in the form, and uses it as you could any other single value, except here you have alreaqdy concatinated the value you want.
Adding a unique ID to each email:I have added a unique ID to each email (using {ct_id} from the database. This solution was not mine, and is lifted direct from another post, but is here for clarity.
Because the ID is added to the database 'after' the email is sent, you cant just put {ct_id} into the email template and have it work. In this example the following code is used to achive that effect:
<?
$cf_id = 0;
$query = "SHOW TABLE STATUS LIKE 'jos_chronoforms_1'";
$result = mysql_query($query) or die ( "Query failed: " . mysql_error() . "
" . $query );
$row = mysql_fetch_assoc($result);
$cf_id = $row['Auto_increment'];
$html_message = str_replace( "#####", $cf_id, $html_message);
?>
(Grey, please correct me if wrong here, this is how I have interpreted your code!)
The code here sets the $cf_id to 0. Then performs an SQL query to get the table with your form submissions in, and queries the number of rows, setting it to $row. $cf_id is then set to the value of $row+1.
The result of which should be the eventual $cf_id of the form when submitted.
However there is one more wrinkle, $cf_id is not set on the form, so within the html it looks for '#####' and replaces it with the result of the look up.
If you look on line 97 of the html template you will see the ##### that gets replaced!
Those would seem to be the main points that may be of interest, I am sure there may be better ways of doing what I have done, but thats what I have managed to implement so far, and thats pretty much all due to help recieved on these forums, hopefully this post will help others who wish to do the same!
I see lots of posts from people who don't code, wondering how far they can get with chronoforms, hopefully this will help to put your mind at rest, as I didnt even know how to write an html form when I started.
Thanks again to all at chrono, I heartily endorse the purchase of the same.
Mizpah
Post edited by: Mizpah, at: 2008/04/10 14:15<br><br>Post edited by: GreyHead, at: 2008/04/14 09:31