• Resolved giuze

    (@giuze)


    Hi, I added 3 different custom fields.
    The problem is the display, if you would add a line break tag at the end of the line 165 of mt-fields-api.php and include the fields as new paragraph on line 169, it would then take same style as the other tickets fields.

    Line 165: $fields .= “<label for=’$name’>” . $field[‘title’] . “</label> ” . $output . “</br>”;
    Line 169: return “<p>” . $fields . “</p>”;

    I didn’t found a good way in the css to make them appear nicely, there’s always this line break missing.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Joe Dolson

    (@joedolson)

    What is the code you’re using to add your custom fields?

    Thread Starter giuze

    (@giuze)

    Hi, This is what’s included

    
    /*
     * Add custom fields to each add to cart form. 
     */
    add_filter( 'mt_custom_fields', 'create_custom_fields', 10, 3 );
    function create_custom_fields( $array ) {
    	// Other fields: sanitize callback; input type; input values; display_callback
    	$array['food_pref'] = array( 
    		'title'=>"Food preferences", 
    		'sanitize_callback'=>'sanitize_callback', 
    		'display_callback'=>'display_callback',
    		'input_type'=>'select',
    		'input_values'=>array( 'I eat all ', 'No meat ', 'No Fish ', 'Vegan ' ),
    		'context'=> '309'
    	);
    	/**
    	 * Add a second custom field by adding more values to the array
    	 *
    	 */
    	 $array['other'] = array( 
    		'title'=>"Other or allergy", 
    		'sanitize_callback'=>'sanitize_callback', 
    		'display_callback'=>'display_callback',
    		'input_type'=>'textarea',
    		'context'=> '309'
    	);
    	/**
    	 * Add a third custom field by adding more values to the array
    	 *
    	 */
    	 $array['presence'] = array( 
    		'title'=>"Will you miss some of the nights? (which one)", 
    		'sanitize_callback'=>'sanitize_callback', 
    		'display_callback'=>'display_callback',
    		'input_type'=>'textarea',
    		'context'=> '309'
    	);
    	return $array;
    }
    
    /* This display callback is used to format the saved data. $context is either 'payment' or 'cart', depending on whether it's appearing in an admin payment record or in the user's cart. */
    function display_callback( $data, $context='payment' ) {
    	return urldecode( $data );
    }
    
    /* This sanitize callback is used to sanitize the data before it's saved to the DB */
    function sanitize_callback( $data ) {
    	return esc_sql( $data );
    }
    Plugin Author Joe Dolson

    (@joedolson)

    Got it; thanks. I’ll look at what I want to do in the next release.

    Thread Starter giuze

    (@giuze)

    Thanks

    Plugin Author Joe Dolson

    (@joedolson)

    Modified in version 1.4.11. It’s not the same as what you did, but it’s what I felt would work best for my goals.

    Thread Starter giuze

    (@giuze)

    Hi, it works well even without having to edit my CSS.
    Thanks for the modification

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Multiple custom fields doesn’t display correctly’ is closed to new replies.