Get label name php

get_field_object()

Each field contains many settings such as a label, name and type. This function can be used to load these settings as an array along with the field’s value.

Parameters

get_field_object($selector, [$post_id = false], [$format_value = true], [$load_value = true]);
  • $selector (string)(Required) The field name or field key.
  • $post_id (mixed)(Optional) The post ID where the value is saved. Defaults to the current post.
  • $format_value (bool)(Optional) Whether to apply formatting logic. Defaults to true.
  • $load_value (bool)(Optional) Whether to load the field’s value. Defaults to true.

Return

(array) This function will return an array looking something like the following. Please note that each field contains unique settings.

array( 'ID' => 0, 'key' => '', 'label' => '', 'name' => '', 'prefix' => '', 'type' => 'text', 'value' => null, 'menu_order' => 0, 'instructions' => '', 'required' => 0, 'id' => '', 'class' => '', 'conditional_logic' => 0, 'parent' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '' ) );

Examples

Display a field’s label and value

This example shows how to load a field and display its label and value.

Display a field’s label and value from a specific post

This example shows how to load a field and display its label and value from the post with >

Retrieve a field using its key

In some circumstances it may be necessary to load a field by its key, such as when a value has not yet been saved. This example shows how to load a field using its key.

Display field type specific data

Some field types store extra data such as the Select field. This example shows how to loop over a Select field’s choices and display them in a list.

On this page

In this category

  • acf_add_options_page()
  • acf_add_options_sub_page()
  • acf_form_head()
  • acf_form()
  • acf_register_block_type()
  • acf_register_form()
  • acf_set_options_page_capability()
  • acf_set_options_page_menu()
  • acf_set_options_page_title()
  • add_row()
  • add_sub_row()
  • delete_field()
  • delete_row()
  • delete_sub_field()
  • delete_sub_row()
  • get_field_object()
  • get_field_objects()
  • get_field()
  • get_fields()
  • get_row_index()
  • get_row_layout()
  • get_row()
  • get_sub_field_object()
  • get_sub_field()
  • has_sub_field()
  • have_rows()
  • Shortcode
  • the_field()
  • the_flexible_field()
  • the_repeater_field()
  • the_sub_field()
  • update_field()
  • update_row()
  • update_sub_field()
  • update_sub_row()
Читайте также:  Html form with signature

Источник

Fetch label and value from form in php

What I now want to do in the php document is to fetch the value and the label and print it in the php document. I can get the value but dont know how to get the lable. Any help would be nice.

  • 3 Contributors
  • 5 Replies
  • 9K Views
  • 6 Years Discussion Span
  • Latest Post 5 Years Ago Latest Post by Rashid_4

You can not get labels after form submission.
You can create hidden type field and value can be same as label, then when form submitted you can get hidden field value for labeling.

Try this code, you will understand how to use hidden field.

'; echo '
Name Label: '.$_POST['name_label']; echo '
Name Value: '.$_POST['name']; echo '
Email Label: '.$_POST['email_label']; echo '
Email Value: '.$_POST['email']; exit; > ?>

All 5 Replies

You can not get labels after form submission.
You can create hidden type field and value can be same as label, then when form submitted you can get hidden field value for labeling.

Does the hidden types need a unique name? Cause I have tried something similar with the the name and value where I give the same name as label but this does not work since "name" needs to have unique names and i have some repeating label namnes. And how would I get these hidden types in my php? I am kind of newbish. Atm I do

foreach($_GET as $name => $value) < echo $name . ': ' . $value."
"; >
'; echo '
Name Label: '.$_POST['name_label']; echo '
Name Value: '.$_POST['name']; echo '
Email Label: '.$_POST['email_label']; echo '
Email Value: '.$_POST['email']; exit; > ?>
Your Name
Your Email
 

"; foreach($_POST as $name => $value) < if($counter == 0) < echo $value.': '; $counter = 1; >else < echo $value."
"; $counter = 0; > $counter2 = $counter2 + 1; if($counter2 == 18) < echo "

if($counter2 == 44) < echo "

"; > if($counter2 == 60) < echo "

"; > if($counter2 == 76) < echo "

"; > if($counter2 == 92) < echo "

"; > if($counter2 == 104) < echo "

"; > if($counter2 == 116) < echo "

"; > > ?>
if (window.print) < document.write(''); >

Where I have one option to the print the form info and now I want to create a email option. So the contect that is on the page is emailed. Whats the best way to do this?

Источник

WPAcademic / get-acf-label-from-name.php

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

/**
* Plugin Name: Get ACF Field Label from Name
* Plugin URI: https://wpacademic.com
* Version: 1.0.0
* Author: Louis Fico
* Author URI: https://profiles.wordpress.org/louis
* Description: Adds function to get ACF field name from its label
* License: GPL2
*/
/**
* Ultimately, you may want to put this in your own class,
* in which case you can put your own namespace here
*/
// namespace AcfMissingFunctions;
// use Exception;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
// avoid function naming collisions
if (!function_exists( 'getAcfLabelByName' ))
function getAcfLabelByName ( $ fieldName )
if (empty( $ fieldName ))
return 'No field name specified' ;
>
// set a default in case there's an exception
$ fieldLabel = 'Not Found' ;
try
/**
* ACF stores the the Labels in the
* wp_posts table, where the ACF label is the title
* and the excerpt is the field name
*/
global $ wpdb ;
$ tableName = " < $ wpdb ->prefix > posts ";
$ labelReturned = $ wpdb -> get_var ( $ wpdb -> prepare ( " SELECT `post_title` FROM ` $ tableName `
WHERE `post_type` = %s AND `post_excerpt` = %s ", 'acf-field' , $ fieldName ));
// grab the post_title from the result
$ fieldLabel = !empty( $ labelReturned ) ? $ labelReturned : 'Not Found' ;
> catch ( Exception $ e )
$ error = $ e -> getMessage ();
error_log(" There was an exception finding the ACF field label by name with the message $ error ");
>
return $ fieldLabel ;
>
>

Источник

PHP get_label_name Examples

PHP get_label_name - 6 examples found. These are the top rated real world PHP examples of get_label_name extracted from open source projects. You can rate examples to help us improve the quality of examples.

/** * Given an object containing all the necessary data, * (defined by the form in mod_form.php) this function * will update an existing instance with new data. * * @global object * @param object $label * @return bool */ function label_update_instance($label) < global $DB; $label->name = get_label_name($label); $label->timemodified = time(); $label->id = $label->instance; return $DB->update_record("label", $label); >
function label_update_instance($label) < /// Given an object containing all the necessary data, /// (defined by the form in mod.html) this function /// will update an existing instance with new data. $label->name = get_label_name($label); $label->timemodified = time(); $label->id = $label->instance; return update_record("label", $label); >
public function archive($label = 0) < $this->load->model('posts_m'); $this->load->model('labels/labels_m'); if (!empty($label)) < $posts = $this->posts_m->get_many_by('label', $label); > else < $posts = $this->posts_m->get_all(); > $currentLabel = !empty($label) ? get_label_name($label) : 'all'; $this->template->set('posts', $posts)->set('currentlabel', $currentLabel)->set('labels', $this->labels_m->get_all())->build('archive.twig'); >

Источник

Получить значение label через input

Здравствуйте, передо мной стоит такая задача, есть набор чекбоксов и лейблов, выглядит это вот так:

form action="" method="post"> input id="firstID" name="city[]" type="checkbox" value="123" /> label class="checkboxLabel" for="firstID">Абакан/label> input id="secondID" name="city[]" type="checkbox" value="321" /> label class="checkboxLabel" for="secondID">Астрахань/label> input type="submit" value="Отправить" name="subs"> /form>

нужно отправить значения label выделенных чекбоксов на почту, причем value чекбоксов трогать нельзя. То есть, фактически, если был выбран чекбокс с то на почту должно придти - "Абакан".
Вопрос:
Можно ли обратиться к label через чекбокс по id, и как это сделать? Или есть еще какие-нибудь методы выполнить это задание?

вот php-скрипт отправки данных:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 // если была нажата кнопка "Отправить" if($_POST['subs']) { $title = 'Заголовок'; $text = "Текст.\n"; $cities = "Города:\n"; //проверяет, какие города были выбраны if (isset($_POST['city'])){ foreach($_POST['city'] as $key=>$value){ $cities .= " \n"; } } $mess = $text.$cities; // $to - кому отправляем $to = 'admin@admin.admin'; // $from - от кого $from='site'; // функция, которая отправляет наше письмо. mail($to, $title, $mess, 'From:'.$from); echo 'Спасибо! Ваше письмо отправлено.'; } ?>

но он присылает набор value

второй день гуглю и ничего.

Заранее прошу прощения, если это тупой вопрос

Источник

Оцените статью