Programmatically create a field to appear first on the first page of the existing multi-page form

Hi, i have a paged form,
im creating an HTML field programmatically for an existing multi-page form.

  1. i would like to add HTML content to the field. how do i do this ?
  2. i would like this field to appear first on the first page of the existing form. it doesnt seem to work, it always appears last in the last page.
    here is my so far code
    Thanks,
add_filter( 'gform_pre_render_52', array(&$this, 'load_partial_entries' ) );

 function load_partial_entries()  {
					
				    $form = GFAPI::get_form( 52 );
				    $new_field_id = GFFormsModel::get_next_field_id( $form['fields'] );
				    $field = GF_Fields::create( array(
				        'type'   => 'html',
				        'id'     => 10000,
				        'formId' => $form['id'],
				        'required' => false,
				        'label'  => 'Service Orders',
				        'class'  => 'col-md-4',
				        'pageNumber'  => 1,
				    ) );
					
					$form['fields'][] = $field;
					GFAPI::update_form( $form ); 
					
					return $form;
					
				}

The $form['fields'][] is what is adding the field at the end of the form. Try array_unshift instead.

Thanks. it now adds the field to the beginning.

  1. as to my first question, how do i add the actual HTML code to this field ?
  2. the title defined is not showing.

The HTML field has a property named content. Anything you want displayed for that field will need to be assigned to that property e.g.

				    $field = GF_Fields::create( array(
				        'type'   => 'html',
				        'id'     => 10000,
				        'formId' => $form['id'],
				        'required' => false,
				        'content'  => 'Service Orders',
				        'class'  => 'col-md-4',
				        'pageNumber'  => 1,
				    ) );
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.