Gravity Forms Personality Quiz Add-On - php

I'm trying to figure out how to hack this plugin Gravity Forms Personality Quiz Add-on. (https://wordpress.org/plugins/gravity-forms-personality-quiz-add-on/)
Basically I've created 4 fields in ACF to add more "weight" to specific questions within the quiz, to essentially 'force' a tiebreaker rather then use the random option tie breaking function the plugin comes with. Within the backend ACF fields we store the numbers of the questions in order of importance (ie. field one has the number 2 in it to denote that question 2 is the most important question in the event of a tiebreaker).
Each answer has a specific letter value associated with it N,I,S or D. In the event of a tie (ie. same number of "N's" & "I's" chosen) the code should cycle through and see if first tiebreaker question (question 2 in this case) has a value of either N or I. If so, then that letter would be the final result. If neither N or I was chosen for question 2 the tiebreaker code should then move on to the next highest weighted question and preform the same test, and so on.
Problem is that it only seems to work for the first quiz and ONLY "Your Love Style Quiz" the partner quiz doesn't work at all.
If anyone has any suggestions on how to get this working please let me know.
Here is the link to the thread and my code: https://wordpress.org/support/topic/tie-breakers-via-acf/

Got this working, seems that having questions prior to the quiz questions were interfering with the quiz results. By moving them to the bottom, the tiebreakers now work as expected.

Related

Conditional Calculations for field entries within Wordpress using PHP

I was wondering if anyone with some experience with PHP could help. I've been trying to figure out if there is a way within WordPress (GravityView) to make calculations based on certain entries within a form and then use conditional logic to display different images dependent on the result from this calculation.
In this case, I am trying to display different images relating to different measures of a client, i.e. their value to our company, their engagement with our company. Taking the example of Satisfaction I have added a field to one of our forms where if a request is completed unsuccessfully with them it will count that entry. However, I then need to sum all these unsuccessful entries so I can relate them to the different levels of satisfaction (the images). i.e if there are 10 unsuccessful entries for a given client they will be given a poor level of satisfaction and if there are 0 they would be given an excellent level of satisfaction. This is not possible to do within a view in gravity view as you cannot use a shortcode within a shortcode. I cannot sum all the entries using [gvmath] for a specific field and then use [gvlogic] to assign the different levels to different images. So I was wondering if there is a way to bypass this by issue by writing the code directly in PHP.
Also, another issue is within the form that is used for the requests there is a field where the member ID is inserted. Each of our individual clients is given a specific member ID and then a page is created for that client where their 'Levels' are displayed. So ideally the PHP code would be able to sum the entries for only that specific member ID and then using the result of that calculation assigns a particular image to it depending on the answer. Is this all getting too complicated and not able to be performed within WordPress? I've been trying to wrap my head around it all week so any help would be greatly appreciated.
I've attached a picture of the specific images that I would like to assign to the different levels.
Let me know if any further context to my issue is required.
Thanks :)
Levels

Associate data with radio buttons inside of gravity form and dynamically output them in Gravity Forms

I am using Gravity Forms to generate conditional responses to users filling out a form.
The user selects the first radio box (first question) and then follows up by checking the second (second question).
Each of the first radio options each have 3 values associated with them.
Depending on the users second answer I need to determine which of the 3 to display in the confirmation message.
It looks something like this.
What is your profession?
Programmer
Lawyer
Doctor
Athlete
User makes a selection.
How long have you been in this profession?
1 Year
2 Years
10 Years
--
Doctors with 1 years experience earn 50,000 USD for example.
Doctors with 2 years experience earn 70,000 USD for example.
Doctors with 10 years experience earn 100,000 USD for example.
Depending on their answer to the second question I need to somehow dynamically insert this data linked to their first option into the response form.
I have over 300 different variable responses so I don't want to manually create 300 different response forms.
I also want to be able to easily change the values (USD amount) associated with the questions so the output is dynamic.
If you know of any out of the box solutions for doing this, even if it is not using the Gravity Froms plugin I would really appreciate that info.
Any direction or guidance you have on implementing this solution would be greatly appreciated.
It sounds like you're looking for Gravity Forms conditional shortcode. Here's an example:
[gravityforms action="conditional" merge_tag="{Profession:2}" condition="is" value="Programmer"]
Content you would like to conditionally display for programmers.
[/gravityforms]
More details here: https://gravitywiz.com/gravity-forms-conditional-shortcode/

How to auto categorise user generated content

I have a system where the user makes a post, this post will include a title, and the post content itself, the content will be anywhere between 20 - 3000 words and consist of plain text.
I also have a set of more then 700 categories, some are top level categories, the rest are subcategories.
When the user enters the content for their post, they need to be prompted with up to 5 relevant categories, selected automatically based on what the user has typed in.
What is the best way to do this, I am using PHP & MySQL, links to any libraries or code samples would be useful.
User perspective
You cannot do this on 1 step in the same page with only php/mysql. There are mainly 2 options for your question.
You also learn/use some client-side language and implement it to do a search without changing the page. I don't know much of it, so I cannot really recommend anything specific, but this thread should help you.
You use a middle page. That said, the user posts it's content, then after sending it you parse it and offer categories for the user to select in the new page. This has the problem that many users might close the window after pressing 'send' in a comment as they expect it to be sent straight, the good thing is that it only uses php/mysql.
Parsing the text
Once again I'm not sure if this is the most efficient way, but I'd try this and keep testing until achieving the result expected:
First, create a list of few keywords for each category. 4 or 5 should do the trick, but it depends greatly on the categories, text and many other factors.
Then, create an array of 10 elements. 5 would be the id of the category and 5 would be the 'score' for each category. You can set, for example, a score of 1 for each keyword found. Remember to asign some values initially or you'll have nothing to compare it to.
Then I'd search each category keywords in the text. If you get an score superior than any of those obtained previously, substitute the minimum one for the new category.
Echo the 5 categories remaining at the end of the script. They should be the 5 more suitable. But keep in mind that there are many more ways to approach this parsing problem.

How do I allow my users to customize their dashboards in PHP

I'm confused on a basic concept. I'm working on a LAMP project where vendors submit products to companies for review. Each company has their own dedicated form that the vendors can access from their dashboard to submit products for review to the companies. Then the companies have their dashboard where they can review these products.
My question is how do I program for the companies to have the ability to switch the questions they want to ask of the vendors? So upon setting up their account I create a form for the companies that include ten questions of their choosing. Obviously there is a way with PHP for the companies to access these ten questions from their dashboard and to swap these questions out for others that will then populate on their forms that show up on the vendors dashboard. Since it affects my database code and my form code I'm confused on how to handle this and I haven't been able to come up with the right search terms for here or google that will show me resources on how to do this. What is the basic concept here? Am I writing code to literally overwrite the php source code for the companies forms page? Or is the database somehow involved with a global list of questions that are chosen? I am sure this is a basic function of php but I have never dealt with it so a "Mr. Potato Head" explanation and a link to a resource from the community would be real helpful.
EDITED:
I may have been asking this question wrong above. This is far more a php question than a MySQL question. I don't understand the concept of customized forms. If a company chooses to swap out one of their questions and I give them a page where they can adjust their questions, what happens after they hit submit and have selected a new set of questions? Do I set the PHP up to completely overwrite the source code of their form page? That doesn't seem right so I am looking for examples of customized forms....
How about you have a table of Questions with lots of possible questions
Then you have a table of Company_Questions which is just a subset of those questions, chosen by the company. You may then add a question to Questions or just create/swap an entry in Company_Questions to the selected Question.
I think you should look at some Data(base) Design books first, because you may be missing some key concepts.
If you have something like this in your database schema:
users(id, name, other params);
questions(id, question);
You need to do a 1:N relationship to save for all customers the questions their want.
user_que(id_user,id_question, order);
Note: the param 'order' is just to specify the order the client want the question, and to clarify you can add more columns if you want to that table.
Well with that you can do the job. Now some SQL
Get the questions from a client
SELECT q.question FROM questions q, user_que uq WHERE uq.id_user = $client_id
Get the clients who have one question
SELECT c.name FROM users c, user_que uq WHERE uq.id_question = $id_question
Hope it helps you.

PHP : inheritance logical (extends)

This may sound as a non related coding question but it's directly related :
The facts: I've developped a website (with symfony) which allows players to search for a team (like a job board). It makes one module only.
The problems I want the website to be even more accurate and make a custom form for each players depending on the game (for example, for those who play "league of legends" they'll have 3 more informations to fill up....)
The solutions?
One module per game (example: http://pastie.org/private/cl48jsrjreukyjmj7jrk8a).
I'm currently developping 1 module per game in order to take in consideration the specific criteria for specific games.
Advantages :
The player enters the informations in relation with his game and does not see/interact the other criteria
Disavantages:
90% of the code are the same between each modules. It takes more time.
Inheritance
I never played with that before so i don't know if it's possible in my case to stick with 1 module for the entire game collection AND taking in consideration the specific criterias for games. In that case it would mean to have 1 template per game and displaying the right template with the right accessors like
($this->getCV()->getPseudo(); / $this->getCV()->getGame()->getSpecificCriteria1();)
If I have read your question correctly, you want to show additional fields for each specific game.
Solution 1
Create a 2 form process. After your first form, you could redirect the user to a second form which depends on their answers. To do this, in your first form, use a redirect to send the user to a game-specific second form.
Solution 2
Pass the name of the game to the template and show a customised partial for the extra form fields. For this you will need a Url with a game parameter like this:
www.example.com/form/show/:game_identifier
Then in your action, read the parameter and pass it to your template.
In the template, show a partial dependant on the game that was passed through. So only show the extra fields if a specific game was chosen before hand.
There are further ways to accomplish this but these 2 sprung to mind first.

Categories