I am looking to build the 'Post Title' based on user input. I have limited PHP knowledge although I was able to write the code below. I can extract the field values using $_Post and combine them into a variable, but I cannot figure out how to write them back to the 'Post Title' field.
I am using the pre-submission hook since I want the title updated before it is saved. I am hoping this is just a silly syntax problem. Can you share how to write to a calculated field value AFTER the form has been filled out and BEFORE it is posted to the database?
PS: If would be awesome if I could have just dynamically combined fields in the form. Perhaps a future feature.
Code:
add_action("gform_pre_submission", "pre_submission_update_title");
function pre_submission_update_title($form){
//create new post title e.g. Truck from Detroit, MI to Seattle, WA (3/20/2009)
$newposttitle = "Truck From: ".$_POST["input_29"].', '.$_POST["input_28"]." to ".$_POST["input_26"].", ".$_POST["input_17"]." (".$_POST["input_27"].")";
//insert new title back into form (Post Title is ID #1)
foreach($form["fields"] as &$field){
if($field["id"] == "1"){
$field["value"] = $newposttitle;
}
}
}