That is correct. post_content is the field for…well…the post content. If you make a post manually in WordPress you fill out the Title field then you fill out the Content field. F2P Therefore has those two fields. It doesn’t make you a copy of your form in the post. I think this is quite clearly explained in the plugin’s description on it home page: https://ww.wp.xz.cn/plugins/form-to-post/
At the bottom of that page shows an example of code that you could use to create a hook that add other fields into the post content. But if you don’t program PHP, you may find this too difficult.
Hey Michael: Thanks for getting back with me. I’m definitely not a programmer, but I don’t mind trying to learn. Trust me, I’ve read through all of the documentation, and I’ve tried a litany of different plug-ins. I’ve got the email notifications set up exactly the way I want them…I’m just totally stuck trying to get the whole form to populate on either a page or a post. Are you referring to this code?
function f2p_consolidate_fields( $form_data ) { // change the function name as needed
$form_title = 'F2P With Hook Example'; // Change this to your form name
if ($form_data->title = $form_title) {
// Next line sets the post_title value
$form_data->posted_data['post_title'] = "Post from {$form_data->posted_data['your-name']}";
// Next line sets the post_content value
$form_data->posted_data['post_content'] =
"This is a post from {$form_data->posted_data['your-name']} with email {$form_data->posted_data['your-email']}";
}
return $form_data;
}
add_filter( 'form_to_post_form_data', 'f2p_consolidate_fields', 10, 1 ); // make sure the function name matches above
If so, what WP file do I need to add that code to? functions.php in my theme? I just don’t know where to start to get this fixed.
Yes, that’s the example to follow.
You start by copying that code.
Delete the line that sets post_title
In the line that sets the post_content is where you want to work.
I suggest start with
$form_data->posted_data[‘post_content’] = “”;
Then between the quotes, copy and past your whole form definition above.
Then every place you have a tag like
[radio radio-tested “Yes” “No”]
replace it with
{$form_data->posted_data[‘radio-tested’]}
When you are done, make sure there are no double quotes in the middle. Only have a double quote at the beginning and end.
Awesome!!! I’ll work on getting that all set up tonight. When I’m done with the code, what do I name the file? Where do I put it? How do I tie it in with Form to Post or Contact Form 7?
Don’t put it in a file, use this plugin: https://ww.wp.xz.cn/plugins/add-actions-and-filters/
the “add_filter” ties it in.
MICHAEL!!! YOU’RE BRILLIANT! One more thing though…here’s my code:
function f2p_consolidate_fields( $form_data ) { // change the function name as needed
$form_title = 'New Change Request'; // Change this to your form name
if ($form_data->title = $form_title) {
// Next line sets the post_content value
$form_data->posted_data['post_content'] =
"New Change Request from {$form_data->posted_data['requester-name']}, {$form_data->posted_data['requester-email']} \n
Implementation Date: {$form_data->posted_data['imp-date']} \n
Implementation Time: {$form_data->posted_data['imp-time']} \n
Duration (What time will the change be finished?): {$form_data->posted_data['dur-time']} \n
Please describe the change (e.g. Why is it needed? What result is expected?): {$form_data->posted_data['textarea-description']} \n
Was the change tested?: {$form_data->posted_data['radio-tested']} \n
If Yes, how was the change tested? If No, why not?: {$form_data->posted_data['textarea-tested']} \n
What is the expected impact to business? (e.g. Will downtime be experienced? What depts will be impacted?): {$form_data->posted_data['textarea-impact']} \n
Is there a rollback plan?: {$form_data->posted_data['radio-rollback']} \n
If Yes, what is the plan? If No why isn't there a rollback plan?: {$form_data->posted_data['textarea-plan']} \n
Contacts (Name, extension, cell of who should be notified if escalation is necessary?): {$form_data->posted_data['textarea-contacts']} \n
RISK ASSESSMENT \n
Can or will the change cause an outage?: {$form_data->posted_data['radio-outage']} \n
Can an entire location or dept be impacted or experience an outage?: {$form_data->posted_data['radio-location']} \n
Is there any risk that a failed change will not be detected immediately?: {$form_data->posted_data['radio-detect']} \n
Will the recovery process take longer than the time to implement?: {$form_data->posted_data['radio-time']} \n
Can or will security or confidentiality be compromised?: {$form_data->posted_data['radio-security']} \n
Supervisor email: {$form_data->posted_data['email-sup']} \n ";
}
return $form_data;
}
add_filter( 'form_to_post_form_data', 'f2p_consolidate_fields', 10, 1 ); // make sure the function name matches above
ALL of the fields populated in the post!!! The ONLY thing left is that any radio answers (all are “Yes” or “No) populate as Array in the post. How can I fix that?
Dude, you are a LIFE SAVER!!! Thank you so much for your help!!!
OK…
instead of
{$form_data->posted_data['radio-security']}
do this:
First, create a new variable just after the
// Next line sets the post_content value
like this:
$radio_security = implode(', ', $form_data->posted_data['radio-security']);
(don’t use “-” in variable names. You can use “_”)
That creates a text string with each array element separated by “, “
Then replace in the text this:
{$form_data->posted_data['radio-security']}
with this:
$radio_security
ALL HAIL MICHAEL SIMPSON!!!
HE IS THE KING OF WORDPRESS!!!
Dude, I seriously cannot thank you enough for ALL of your help. The form is doing exactly what I wanted it to. Now I get to have fun with mail notifications! Thanks again!!!
Hi, jbach2003 and Michael,
I would like to ask you about the code above.
I tried to write it my own but I have no idea how I should do…
If you do not mind, would you please share your code as a sample?
And also please show or guide me the setting up procedure.
From Michael’s advice, I understand that to set up code, we use “Add Shortcodes Actions And Filters”.
I will wait for you reply.