Skip Navigation

[Closed] Modify layout for post form

This support ticket is created 2 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#2114181

Hello Team,

I want to modify the taxonomy field as a radio button, on item hover I want to call item description, and on the left of the item label, want to call taxonomy custom field value.

For more details please see below video link.
hidden link

Toolset Form Link: hidden link
Reference field layout: hidden link

You can do configure/apply steps what you want or provide me any solution for the same.

Waiting for your reply on the same.

#2114657

Hello, I see the screen recording and I think I understand what you would like to achieve. There's nothing exactly this type of input field structure built-in to Toolset Forms, so you must create it with custom code in the Form Builder, using Expert Mode. I would begin by hard-coding the HTML for the design directly in the Form builder. To access term field values, use the Types termmeta shortcode as explained in our documentation here: https://toolset.com/documentation/customizing-sites-using-php/functions
For example, to get the color code HEX and SUDU level numbers you would use the following shortcode syntax:

HEX: [types termmeta="color-code-hex" output="raw" term_id="123"][/types]<br />
SUDU: [types termmeta="sudu-level" output="raw" term_id="123"][/types]

I am assuming the field slugs are color-code-hex and sudu-level so you may need to adjust those. The term_id attribute should match the term ID you want to display. Another example showing how you might use the hex value in a CSS style attribute as the background color behind the SUDU level text:

<div style='height:30px; width:30px; color:#000; background-color:[types termmeta="color-code-hex" output="raw" term_id="123"][/types]; padding:10px; margin:0;'>[types termmeta="sudu-level" output="raw" term_id="123"][/types]</div>

So you'll use those types of shortcodes to build the HTML for the form elements. The term description is not easily available with any Toolset shortcode. I have seen another ticket with an example custom shortcode you can use for the same purpose:
https://toolset.com/forums/topic/display-taxonomy-description-in-parametric-search-results/#post-309549

add_shortcode('get-term-desc', 'get_term_desc');
  
function get_term_desc($atts) {
    $term_id = $atts['id'];
    $tax_slug = !empty($atts['tax'])?$atts['tax']:'post_tag';
  
    return term_description($term_id, $tax_slug);
}

Use it like this with the term ID and subjective distress taxonomy slug:

[get-term-desc id="123" tax="distress-taxonomy-slug"][/get-term-desc]

Then you will use the Forms PHP API to set the correct term for the new posts created by the Form, based on the User's selected field term value.

To create the input fields in the Form, you can use basic HTML radio inputs like these, where the value for each radio input is equal to the term ID:

Term 1: <input type="radio" name="custom-distress-taxonomy" value="123" />
Term 2: <input type="radio" name="custom-distress-taxonomy" value="456" />
Term 3: <input type="radio" name="custom-distress-taxonomy" value="789" />

I chose the name "custom-distress-taxonomy", but that is arbitrary. Then you can use our Forms API cred_save_data to add the correct term to the new post. Here is an example showing how to use this API to get the value of the selected radio field and use it to set a taxonomy term on the new post:

// set custom taxonomy term in new post based on selected generic radio input
// https://toolset.com/forums/topic/modify-layout-for-post-form/
add_action('cred_save_data', 'tssupp_set_distress_level',10,2);
function tssupp_set_distress_level($post_id, $form_data) {
  $forms = array( 123 );
  $taxonomy = 'distress-taxonomy-slug';
  $radio_field_slug = 'custom-distress-taxonomy';

  // you should not edit below this line
  if ( in_array( $form_data['id'], $forms ) )
  {
    $distress_term_id = isset($_POST[$radio_field_slug]) ? $_POST[$radio_field_slug] : 0;
    if( $distress_term_id ) {
      wp_set_object_terms($post_id, $distress_term_id, $taxonomy, false);
    }
  }
}

Replace 123 with the numeric ID of the Form that creates new posts. Replace distress-taxonomy-slug with the slug of the Subjective Distress taxonomy, and replace custom-distress-taxonomy with the radio input slug if you chose a different input field name in the Form builder.

The topic ‘[Closed] Modify layout for post form’ is closed to new replies.