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?
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
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
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
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
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
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
My issue is resolved now. Thank you!