Support » Plugin: Form to Post » CF7 form to post

  • Resolved jbach2003

    (@jbach2003)


    I have a form with 18 different fields to fill out. I need the entire form (all 18 fields) to post to a page (or post) when submitted. I have successfully gotten wordpress to generate a post, but only with a title (using CF7 short code post_title) and with one other field (using CF7 short code post_content). It’s almost like I need to use post_content on every field, but whatever field I set as post_content first is the ONLY one that gets submitted. I need the WHOLE form, not just one field! I’ve been at this for weeks and I’m about to completely give up. Can someone PLEASE HELP?????? Here’s what my form looks like in CF7:

    <p>Change Request Title (multiple words need "-" between them e.g. Test-Change):<br />
    [text* post_title] </p>
    
    <p>Name:<br />
        [text* requester-name] </p>
    
    <p>Your Email:<br />
        [email* requester-email] </p>
    
    <p>Implementation Date:<br />
        [date* imp-date] </p>
    
    <p>Implementation Time:<br />
    [time* imp-time time-format:HH:mm] </p>
    
    <p>Duration (What time will the change be finished?):<br />
    [time* dur-time time-format:HH:mm] </p>
    
    <p>Please describe the change (e.g. Why is it needed? What result is expected?):<br />
    [textarea* post_content] </p>
    
    <p>Was the change tested?:<br />
    [radio radio-tested "Yes" "No"] </p>
    
    <p>If Yes, how was the change tested? If No, why not?:<br />
    [textarea* textarea-tested] </p>
    
    <p>What is the expected impact to business? (e.g. Will downtime be experienced? What depts will be impacted?):<br />
    [textarea* textarea-impact] </p>
    
    <p>Is there a rollback plan?:<br />
    [radio radio-rollback "Yes" "No"] </p>
    
    <p>If Yes, what is the plan? If No, why isn't there a rollback plan?:<br />
    [textarea* textarea-plan] </p>
    
    <p>Contacts (Name, extension, cell of who should be notified if escalation is necessary?):<br />
    [textarea* textarea-contacts] </p>
    
    <h3>RISK ASSESSMENT</h3><br />
    
    <p>Can or will the change cause an outage?<br />
    [radio radio-outage "Yes" "No"] </p>
    
    <p>Can an entire location or dept be impacted or experience an outage?<br />
    [radio radio-location "Yes" "No"] </p>
    
    <p>Is there any risk that a failed change will not be detected immediately?<br />
    [radio radio-detect "Yes" "No"] </p>
    
    <p>Will the recovery process take longer than the time to implement?<br />
    [radio radio-time "Yes" "No"] </p>
    
    <p>Can or will security or confidentiality be compromised?<br />
    [radio radio-security "Yes" "No"] </p>
    
    <p>Supervisor's email:<br />
    [email* email-sup] </p>
    
    <p>[submit "Post"]</p>

    https://wordpress.org/plugins/form-to-post/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    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://wordpress.org/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.

    Plugin Author Michael Simpson

    (@msimpson)

    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?

    Plugin Author Michael Simpson

    (@msimpson)

    Don’t put it in a file, use this plugin: https://wordpress.org/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!!!

    Plugin Author Michael Simpson

    (@msimpson)

    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.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘CF7 form to post’ is closed to new replies.