Support

Account

Home Forums General Issues Custom ACF Field Type – Phone number

Solving

Custom ACF Field Type – Phone number

  • Hi,

    i would like to create a new custom field type “phonenumber”.
    A field type with 4 input fields (country-prefix, area-code, number, direct-dialing).

    My create_field-Function:

    function create_field( $field )
    	{
    		global $post;
    		$field = array_merge($this->defaults, $field);
    		?>
    		<table border="0">
    			<tr>
    				<td><div class="acf-input-prepend"><?= $field['country-prefix']; ?></div></td>
    				<td><div class="acf-input-wrap"><input type="text" id="<?php echo $field['key']; ?>" class="<?php echo $field['class']; ?> acf-is-prepended" name="<?php echo $field['name']."['country-prefix']"; ?>" value="" placeholder="Landesvorwahl" /></div></td>
    				<td><?= $field['seperator'] ?></td>
    				<td><div class="acf-input-wrap"><input type="text" id="<?php echo $field['key']; ?>" class="<?php echo $field['class']; ?>" name="<?php echo $field['name']."['area-code']"; ?>" value="" placeholder="Ortsvorwahl" /></div></td>
    				<td><?= $field['seperator'] ?></td>
    				<td><div class="acf-input-wrap"><input type="text" id="<?php echo $field['key']; ?>" class="<?php echo $field['class']; ?>" name="<?php echo $field['name']."['phone-number']"; ?>" value="" placeholder="Nummer" /></div></td>
    				<td><?= $field['seperator'] ?></td>
    				<td><div class="acf-input-wrap"><input type="text" id="<?php echo $field['key']; ?>" class="<?php echo $field['class']; ?>" name="<?php echo $field['name']."['direct-dialing']"; ?>" value="" placeholder="Durchwahl" /></div></td>
    			</tr>
    		</table>
    		<?php
    	}

    Unfortunately, nothing is saved…

    Has anybody a tip for me?

  • Now I have managed to store the data.
    But now, there is a problem to get the value from the db.

    The saved data looks like:
    a:4:{s:14:"country_prefix";s:2:"43";s:9:"area_code";s:1:"1";s:12:"phone_number";s:6:"666666";s:14:"direct_dialing";s:4:"0111";}

    But, when i debug the $field var at the backend output i only get this data:

    Array
    (
        [seperator] => -
        [country-prefix] => +
        [key] => field_54848f4ff3185
        [label] => test
        [name] => fields[field_54848f4ff3185]
        [_name] => test
        [type] => phonenumber
        [order_no] => 26
        [instructions] => 
        [required] => 0
        [id] => acf-field-test
        [class] => phonenumber
        [conditional_logic] => Array
            (
                [status] => 0
                [rules] => Array
                    (
                        [0] => Array
                            (
                                [field] => field_545fc78e1d45a
                                [operator] => ==
                                [value] => 0
                            )
    
                    )
    
                [allorany] => all
            )
    
        [field_group] => 137
        [value] => 
    )

    The value is missing…
    …also in the frontend

  • Hi @hcmedia

    Did you find a solution for this?
    Where did you place the debug code to output $field?

    Also, what version of ACF are you using?

    Thanks
    E

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Custom ACF Field Type – Phone number’ is closed to new replies.