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

    (@msimpson)

    After a post is created via a form, the post would be shown on a site just like a post you create manually. You should also see it under “Posts” in WP admin where you can edit it.

    Thread Starter deserteagle

    (@deserteagle)

    It shows up, but again, only displays the shortcode in the WP admin… and going back to that post on the front-end shows nothing.

    Plugin Author Michael Simpson

    (@msimpson)

    I’m totally confused whether you are talking about a post with the form or some shortcode or the post created by the form.

    Thread Starter deserteagle

    (@deserteagle)

    No worries, I understand. Took me a while to figure it out myself, so here goes.

    The page shows the form just fine: http://imgur.com/ueFykh4

    The form submits and becomes a post: http://imgur.com/GByRsil

    The post appears in the admin: http://imgur.com/hoeK0GP

    But the post itself does not show what I typed in: http://imgur.com/JfAwXtS

    Instead it shows the shortcode I put in the page to get the contact form to show: http://imgur.com/r1oxL5z

    Plugin Author Michael Simpson

    (@msimpson)

    That helps. Weird that the short code is there.

    Would you paste in here your form definition? (Please format as code)

    Thread Starter deserteagle

    (@deserteagle)

    [hidden post_title]
    [hidden post_content "application"]
    [hidden post_category_name "Duct Seal"]
    [hidden ID]
    
    <p>Equipment Make*
    [text* text-227 id:make]</p>
    <p>Start-up Date*
    [text* text-8 id:startupdate]</p>
    <p>Model #*
    [text* text-246 id:condensermodelnumber]</p>
    
    <p>[submit "Send"]</p>

    Here are the modifications I did to FormToPost_Plugin.php

    $post = array(
    #            'post_status' => 'publish',
                'post_status' => 'pending',                              # initial rebate application status
                'post_type' => 'post',
                'post_category' => array(0)
            );

    And here are the modifications I did to the hidden.php of Contact Form Module

    global $post;
    	date_default_timezone_set(get_option('timezone_string'));				# sets the timezone used from the wordpress selection
    	$rebate_time = date("m/d/Y @ h:ia");													# rebate application timestamp
    	$rebate_type = get_the_title();
    	if(is_object($post)) {
    
    		switch($sanitized_name) {
    			case 'post_title':
    			case 'post-title':
    				#$value = $post->post_title;
    				$value = $rebate_type." submitted on " .$rebate_time;                        # rebate application title
    				break;

    Plugin Author Michael Simpson

    (@msimpson)

    Ok, I was a little confused, but I now understand that http://imgur.com/r1oxL5z is the view of the page with the form, not the post listed in http://imgur.com/hoeK0GP

    I assume if you open http://imgur.com/hoeK0GP then you see an empty post. This is because there is nothing in the post_content field. Whatever is in post_content in the form becomes the content of the post.

    If you want to get the other form values (make, startdate, etc.) then you need to find a way of copying that information into the post_content field. You can try to do this (1) on the front end using some Javascript prior to submit or (2) register a hook in CF7 or (3) modify FormToPost_Plugin.php to do it. I would recommend (2).

    In fact I think you can avoid changing code in hidden.php and my plugin by using a CF7 hook instead. If you modify a plugin, then you loose your changes if you update the plugin. Using a hook is a better way to go.

    I’ll suggest my own Add Actions and Filters plugin which gives you an admin page to place PHP code in. Then I would put code like this leveraging CF7’s wpcf7_posted_data hook (I haven’t tested it! Just giving you an idea).

    function set_form_to_post_values($posted_data) {
        $posted_data['post_status'] = 'pending';
    
        $posted_data['post_content'] = 'Make:' . $posted_data['text-227] . '<br/>Start Update:' . $posted_data['text-8'] . '<br/>Model:' . $posted_data['text-246'];
    
        date_default_timezone_set(get_option('timezone_string'));
        $rebate_time = date("m/d/Y @ h:ia");
        // Actually get_the_title() won't work here in the hook callback functions...
        // ... might try adding javascript to page to set the value of a hidden field
        // which could be accessed here.
        // see http://stackoverflow.com/questions/18023030/how-to-get-post-title-by-javascript-before-submission
        $rebate_type = 'TBD'; //get_the_title();
        $posted_data['post_title'] = $rebate_type." submitted on " .$rebate_time; 
    
        return $posted_data;
    }
    
    add_action('wpcf7_posted_data', 'set_form_to_post_values');
    Thread Starter deserteagle

    (@deserteagle)

    Thank you so much! Your Add Actions and Filters plugin ROCKS, by the way!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Editing posts’ is closed to new replies.