Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to make highly interactive Wordpress site WordPress

I don't know id this is possible, but here is my question: how can I make a Wordpress website with the following properties:

<strong>1. It has forms that the user can input text in</strong> (this I know how to do).

<strong>2. This text input is labeled with a certain tag - depending on the form it was entered in - and stored in a database.</strong>

<strong>3. I can define new sentences that use the stored text.</strong>

An example:
- A form asks: "What is your favorite animal?".
- Say the answer is "lion", then this text is stored with the tag "#fav_anim = lion"
- I can show a text like "What would you say to a #fav_anim when you met it in the street?" and the system would automatically fill in the variable, resulting in: "What would you say to a lion when you met it in the street?"
<strong>
4. Based on the input that is stored in the database, and certain rules, certain texts may be triggered.</strong>

An example
- The database has age (#age) of the user stored (which they have put in before).
- Say I define three age groups: young, middle aged and old (let's call this #age_group)
- Say I define this rule: If #age = < 20 then #age_group = "young" ; If #age = > 20 and < 50 then #age_group = "middle aged" ;If #age = > 50 then #age_group = "old";\
- Then when I would show the sentence: "You are a #age_group person" teh system woudl automatically show "You are a young person" , if #age = < 20.

<strong>4. Based on the choices the user makes in menus (like drop down or radio button) a different page would be shown. The sequence of pages is determined by the choices of the user.</strong>

An example:
- Would you like some more information on this? Radio buttons 'Yes' and 'No'
- Yes: page 1 is shown, No: page 2 is shown.

<strong>5. The next time the user visits the site, all his data is available.</strong>

An example
- When the visitor logs in, the variable #first_name is available for this person from their earlier visit(s).
- Let's say #first_name = Jack
- So I can say "Hi #first_name, welcome back!" and the system will automatically show: "Hi Jack, welcome back".

<strong>6. Based on the behavior of the visitor, certain variables are filled.</strong>

An example:
In the database a variable #visit_number is maintained. Every time the user visits, this is augmented by 1. So during their first visit, #visit_number = 1, when they visit again #visit_number is set to 2 and so on.

Another example:
- When they reach a page 25, or check a certain button, they have finished a certain sequence.
- Database maintains a variable called #sequence1_finished = 0 When they finish the sequence, this is set to #sequence1_finished = 1

<strong>7. Based on variables saved for that user in the database, the site starts with a certain page when the user comes back. </strong>

An example
The user logs in and has #sequence1_finished = 1 in their data, then the siet starts up with page number 26 rather than page 1.

Answers (3)

2012-10-14

Bryan Headrick answers:

This sounds like a job for Gravity Forms


jaaph comments:

I have Gravity forms, premium version, but I don't think it can do all the things I listed, or can it?

2012-10-14

Kyle answers:

Yes, this is absolutely all possible.

For questions 1 and 2 Gravity form is a good choice because they have a field input called a 'Custom Field'. http://codex.wordpress.org/Custom_Fields

You can manage custom fields with plugins like Advanced Custom Fields, More Fields, or Types. A custom field will do the job for question 3. For question 4, you can simply call the information store in the custom field by user.

If you go with the gravity forms user-registration add-on you can add custom fields to the user profile very easily, so each user could have their favorite animal or whatever stored in their user meta. From their everytime you want to reference something for a specific user like you described you can do something like <?php global $user; get_currentuserinfo(); echo current_user->favorite_animal' or something along those lines. This is definitely the easiest way to store user meta, but you can of course do this manually, by adding fields to the default wordpress registration form

Gravity forms also offers the ability to display or hide fields through 'conditional logic' which will determine the pages as you say by customer choices.

As far as 6 and 7 you are getting in to custom functions and conditoinals. Everything you described is certainly possible, but will take some custom work. As far as checking the user for sequence completion, this can be done with a radio field that is stored as a custom field for the user, and a conditional that checks the value. Something like making two choices, with values of 1 and 0, with 0 as the default and 1 if it the radio is clicked and then making a conditional that does if( $current_user->$radio_button value > 0) {whatever you want to do} else { what it is if they don't finish the sequence}.

Long story short this is all very possible. Your best bet is to look in to the various form plugins, and how to add custom fields for users to add to their profiles. I can help with any of this as well

2012-10-14

John Cotton answers:

Er...why can't you just code the logic. Nothing you've describe above is complicated - in fact, I'd say it was convoluted but simple.

I lost count a bit but if seems like around 8 - 10 states (for the user) and then some logic applied with a few if or switch statements. You could almost certainly use user meta data to maintain the state information and - depending on what you need for page layout, do it in one or two page templates.


jaaph comments:

Hi John,
Thank you for your reply!

Two questions. What exactly do you mean by 'just code the logic'? I mean, what kinds of activities make up 'coding' in this case?

I looked up 'convoluted' in the dictionary and the closest synonym seems to be 'complicated'. So if I udnerstand you right, you are saying: it is complicated, yet simple. Could you please explain why that is?

BR
Jaap


John Cotton comments:

Convoluted would better be defined as complex due to its length - so in your case it's a series of very simple steps, but there are lots of them!

So pseudo-code might be something like:


<?php
global $current_user;

$ud = get_userdata($current_user->ID);

echo "Welcome back $current_user->first_name";


$step = get_user_meta( $current_user->ID, '_current_step', true );

switch( $step ) {
case 1:
echo 'A TEXT BOX FOR FAV ANIMAL';
break;

case 2:
$animal = get_user_meta( $current_user->ID, '_fav_animal', true );
echo "What would you say to a $animal when you met it in the street?";
break;

// etc
}
?>


And then capturing data as you go...


<?php
if( isset($_POST['fav_animal']) ) {
update_user_meta( $current_user->ID, '_fav_animal', $_POST['fav_animal']);
update_user_meta( $current_user->ID, '_current_step', 2);
}
?>


Clearly you'd want to organise the above into logical routines and set it within you page layout, but it's not complicated....just convoluted :)