Skip Navigation

[Resuelto] Do hidden parent post type input fields need to be of the select type?

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:

Change the CRED form parent select dropdown into a hidden field.

Solution:

there isn't such a built-in feature. as a workaround you can use a generic hidden field to replace the select dropdown field, for example:

[cred_generic_field field='_wpcf_belongs_product-listing_id' type='hidden' class='' urlparam='productid']
{
"required":0,
"validate_format":0,
"default":"0"
}
[/cred_generic_field]

https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field

Then update the field value with CRED action hook "cred_save_data", for example:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==123)
    {
        if (isset($_POST['_wpcf_belongs_product-listing_id']))
        {
            // add it to saved post meta
            update_post_meta($post_id, '_wpcf_belongs_product-listing_id', $_POST['_wpcf_belongs_product-listing_id'], true);
        }
    }
}

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created hace 6 años, 7 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Este tema contiene 3 respuestas, tiene 2 mensajes.

Última actualización por Luo Yang hace 6 años, 7 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#730673

Pretty much all my CRED forms that set a "belongs" parent post ID are hidden and populated using a URL parameter. However, the HTML generated is still a select box even though it's hidden. I'm now realizing that some of the HTML that could get generated as the site grows might become incredibly long with hundreds (someday thousands?) of useless <option>'s that don't even get used because they're all hidden.

Is there a way to make the hidden field just a text line instead of a select box? For example:

[cred_field field='_wpcf_belongs_product-listing_id' value='' urlparam='productid' class='hidden' output='bootstrap']

becomes...

<input type="hidden" name="_wpcf_belongs_product-listing_id" value="999">

NOT...

<select name="_wpcf_belongs_product-listing_id">
  <option value="1">Item 1</option>
  <option value="2">Item 2</option>
  ...
  <option value="999" selected="selected">Item 999</option>
</select>

If this isn't currently possible, can you add it as a feature request? For some of the functionality I'm building into the site, I suspect some of this HTML will get quite large unnecessarily. Apologies if there is some obvious way to do this that I somehow missed.

Thanks.

- Aaron

#731536

Dear Aaron,

You are right, there isn't such a built-in feature. as a workaround you can use a generic hidden field to replace the select dropdown field, for example:

[cred_generic_field field='_wpcf_belongs_product-listing_id' type='hidden' class='' urlparam='productid']
{
"required":0,
"validate_format":0,
"default":"0"
}
[/cred_generic_field]

https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field

Then update the field value with CRED action hook "cred_save_data", for example:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==123)
    {
        if (isset($_POST['_wpcf_belongs_product-listing_id']))
        {
            // add it to saved post meta
            update_post_meta($post_id, '_wpcf_belongs_product-listing_id', $_POST['_wpcf_belongs_product-listing_id'], true);
        }
    }
}

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#738525

Thanks - I'll start doing this moving forward and if the feature becomes built in someday then I will go through and eliminate the excess PHP.

- Aaron

#738828

You are welcome