Support » Plugin: Form to Post » Form Fields

  • Hi.
    I am using this plugin in site and made custom fields to post like
    {$form_data->posted_data[‘select-family’]}
    {$form_data->posted_data[‘translator’]} the language is{$form_data->posted_data[‘select-language’]}
    I made another form which do not include these fields when I submit that form the the helping text like “the language is” also showing.
    How to solve this?

    • This topic was modified 3 years, 10 months ago by moni.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    Options:

    (1) The code should only run for a specific form if you set it up like the example
    if ($form_data->title = $form_title) ...
    So you could set up different filter functions for different forms

    (2) Or you can use the same filter function for multiple forms, but add “if” statements based on what fields are submitted. For example:

    $content = '';
    if (isset($form_data->posted_data['select-family']) {
      $content .= $form_data->posted_data[‘select-family’] . ' ';
    }
    if (isset($form_data->posted_data['translator']) {
      $content .= $form_data->posted_data[‘translator’] . ' ';
    }
    if (isset($form_data->posted_data['select-language']) {
      $content .= "the language is {$form_data->posted_data[‘select-language’]}";
    }
    $form_data->posted_data['post_content'] = $content;
    
    $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']}";

    Thank you for reply
    I made different forms and by setting form title in which this code is common:
    “This is a post from {$form_data->posted_data[‘your-name’]} with email {$form_data->posted_data[‘your-email’]}
    {$form_data->posted_data[‘select-family’]} {$form_data->posted_data[‘translator’]} the language is{$form_data->posted_data[‘select-language’]}
    {$form_data->posted_data[‘Urgent-Service’]} on date{$form_data->posted_data[‘your-date’]}

    Now i added more content after this code in different form like

    for {$form_data->posted_data[‘picnic-planning’]}

    now post is not showing content after date. the post data code is same in form and in function. The post is like this:

    This is a post from julia with email test@test.com
    Family A Translator Required the language isChinese
    Urgent Service Not Require on date for Array

    Not showing content after date form my multiple forms.

    By activating code for other forms the post does not show the content written after common content of all forms.

    Plugin Author Michael Simpson

    (@msimpson)

    It sounds like you just need to debug your own code.

    I wrote code for different form with different function names. I am using shortcode , action filters.
    The code works perfectly if other forms code is deactivated and stop working when all forms code activated. I tried by changing name of post field code for example: destination to t-destination to differentiate it from other fields but still nothing happen when code is activated for all forms. If you understand this problem then guide me please.

    By trying second method Now I write code , to work for multiple forms.But it is generating error not working.Please check am I writing in right way.. Error is generated at line 7.

    function f2p_consolidate_fields( $form_data ) { // change the function name as needed
    $form_title = ‘Help Form’; // 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’]}”;
    $content = ”;
    if (isset($form_data->posted_data[‘transport_service’]) {
    $content .= $form_data->posted_data[‘transport_service’] . ‘ ‘;
    }
    if (isset($form_data->posted_data[‘Destination’]) {
    $content .= “for {$form_data->posted_data[‘Destination’] }”;
    }
    if (isset($form_data->posted_data[‘pickup-address’]) {
    $content .= “pickup address is {$form_data->posted_data[‘pickup-address’]}”;
    }
    if (isset($form_data->posted_data[‘pickup-city’]) {
    $content .= “from city {$form_data->posted_data[‘pickup-city’]}”;
    }
    if (isset($form_data->posted_data[‘pickup-state’]) {
    $content .= “state is {$form_data->posted_data[‘pickup-state’]}”;
    }

    $form_data->posted_data[‘post_content’] = $content;

    // 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’]}
    {$form_data->posted_data[‘select-family’]} {$form_data->posted_data[‘translator’]} the language is{$form_data->posted_data[‘select-language’]}
    {$form_data->posted_data[‘Urgent-Service’]} on date{$form_data->posted_data[‘your-date’]}

    “;
    }
    return $form_data;
    }
    add_filter( ‘form_to_post_form_data’, ‘f2p_consolidate_fields’, 10, 1 ); // make sure the function name matches above

    Plugin Author Michael Simpson

    (@msimpson)

    Post your code in http://phpcodechecker.com/

    Hi.
    First of all thank you so much for support.
    I almost figure out problem.. I have multiple forms I used this method for posting of multiple forms.
    if ($form_data->title = $form_title) …
    When there are multiple forms some thing in checkbox inside posting code it does not post. I used select boxes it started posting.
    There is some problem in plugin when posting with checkbox having multiple forms it does not work. Please have a look on that.

    • This reply was modified 3 years, 10 months ago by moni.
    Plugin Author Michael Simpson

    (@msimpson)

    I would need a complete example including form definition and hook code to reproduce the problem.

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