PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Populating fields without a filter

  1. So, I used to use this kind code:

    $form['fields']['1']['defaultValue']=$current_user->data->user_email;
    $form['fields']['0']['defaultValue']['1.3']=$user_info->user_firstname;
    $form['fields']['0']['defaultValue']['1.6']=$user_info->user_lastname;
    $form['fields']['2']['defaultValue']=get_user_meta( $current_user->ID, 'bedrijfsnaam', true );
    $form['fields']['3']['defaultValue']['4.1']=get_user_meta( $current_user->ID, 'straatnaam', true );
    $form['fields']['3']['defaultValue']['4.3']=get_user_meta( $current_user->ID, 'postcode', true );
    $form['fields']['3']['defaultValue']['4.5']=get_user_meta( $current_user->ID, 'plaats', true );

    Which works perfect until you change around the order of the fields for example. It was intuitive to me, but not supported I guess.

    What I would like is that the field number would not be incremental. Now the first is $form['fields']['0'], the second is $form['fields']['1'], etc. But would get the ID of the field.

    Posted 6 years ago on Thursday May 23, 2013 | Permalink
  2. Until then you can use something like:

    foreach($form['fields'] as &$field){
    	$id=$field['id'];
    
    	switch($field['type']){
    		case 'checkbox':
    			$f=json_decode($meta['f'.$id][0],true);
    			foreach($field['choices'] as &$choice){
    				if($f[$choice['value']]=='1'){
    					$choice['isSelected']='true';
    				}
    			}
    		break;
    		case 'textarea':
    		case 'text':
    		case 'website':
    			$field['defaultValue']=$meta['f'.$id][0];
    		break;
    		case 'radio':
    			foreach($field['choices'] as &$choice){
    				if($choice['value']==$meta['f'.$id][0]){
    					$choice['isSelected']='true';
    				}
    			}
    		break;
    	}
    	if($id=='43'){
    
    		//$field['description']='<div id="creditinfo">oke</div>'.$field['description'];
    
    	}
    }
    Posted 6 years ago on Monday May 27, 2013 | Permalink