Skip Navigation

[Resolved] CRED Form: Access parent id in "cred_save_data" Hook

This support ticket is created 2 years, 6 months ago. 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.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by Jennifer 2 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#2425511

Tell us what you are trying to do?
I try to access the post id of the parent (Field: [cred_field field='@kunde-projekt.parent' class='form-control' output='bootstrap' select_text='---Select customer---' required='false']) after I submit a child post form. However I am not sure, how I have to adress this field appropriately in my php cred_save_data hook. I have tried $_POST['wpcf-@kunde-projekt.parent'], but it doesn't work.


add_action('cred_save_data', 'projekt_update_after_anlegen',10,2);
function projekt_update_after_anlegen ($post_id, $form_data)
{
if ($form_data['id']==1834) {

// I need help accessing the select parent field 
$kundenid = $_POST['wpcf-@kunde-projekt.parent'];
$kundenname = get_the_title($kundenid);
update_post_meta( $post_id, 'wpcf-projekt-kundenname', $kundenid . ' / ' . $kundenname );
}
}

[credform]
[cred_field field='form_messages' class='alert alert-warning']

[cred_field field='post_title' class='form-control' output='bootstrap']
[cred_field field='@kunde-projekt.parent' class='form-control' output='bootstrap' select_text='---Select customer---' required='false']
	
[cred_field field='form_submit' output='bootstrap' value='Projekt speichern' class='btn btn-primary btn-lg']
[/credform]

Is there any documentation that you are following?
no

Is there a similar example that we can see?
no

What is the link to your site?

#2425559

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jennifer,

Thank you for getting in touch.

In order to get the correct parameter for the parent field, you will perhaps need to check the payload for the Post request.

If you're not sure how to do this then you can send me a link to the form so that I can have a look for you.

Thanks,
Shane

#2425605

Hi Shane,

Unfortunately I don't know how to check the payload.

Here is the Link to the Form:
hidden link

Thank you for your help
Jenny

#2425615

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jennifer,

Thank you for the link.

Try getting the parent data with this slug "@kunde-projekt.parent"

So you should have.
$kundenid = $_POST['@kunde-projekt.parent'];

Thanks,
Shane

#2425627

Hey Shane,

many thanks for your help.
However I have encountered a problem. If I access $kundenid in the following way:
$kundenid = $_POST['@kunde-projekt.parent'];
$kundenid is empty.

What can be the cause of the problem?

Kind regards
Jenny

#2425713

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jenny,

Can you try it with the @ sign removed from the name.

If this doesn't work would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?

I've enabled the private fields for your next response.

Thanks,
Shane

#2426597

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jennifer,

I was able to get this to work now. In the case of the Parent field the ".parent" gets replace with "_parent" in the post request data.

The correction is.

$kundenid = $_POST['@kunde-projekt_parent'];

Thanks,
Shane

#2428639

My issue is resolved now. Thank you!