Xhynk
Xhynk

Reputation: 13880

Dynamically Populate Custom Field (Gravity Forms)

I've got a form that calculates how many times a person has chosen a value. Each question has 3 answers with a value of either "self", "others", or "social". Whichever has the MOST gets returned as the result.

Ultimately, I need a custom post field hidden from the user, populated with this result. Currently it's being display after form submission with:

return $confirmation

I've got http://pastie.org/3312298 pasted in the bottom of my functions.php file.

I'm not quite sure how to get the result into the box before the form gets submitted to us as an entry.

www.webdesignsalemoregon.com/surveytest

is where it's lying right now

Upvotes: 1

Views: 1651

Answers (1)

phpguy
phpguy

Reputation: 11

You're taking a way complicated route of doing this.

give each radio button for 'self' <input name='self'>, and do the same for the rest

$self_answers = count($_POST['self']);
$others_answers = count($_POST['others']);
$social_answers = count($_POST['social']);

$max = max($self_answers, $others_answers, $social_answers) ; 

if($max == $self_answers) {
    $greatest = "self";
} else if($max == $others_answers) {
    $greatest = "others";
} else {
    $greatest = "social";
}

Upvotes: 1

Related Questions