Skip Navigation

[Gelöst] Register for Event

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
How can I set a Post that is submitted with CRED, to be child to the Post, where the Form is inserted?
I also need to update it's title with a value coming from a Post Field

Solution:
You will use a Custom CRED API (cred_save_data) and Wordpress API (mainly get_ and update_post_meta) to achieve this

You will put the function created into your Theme's functions.php

In the Code, you will:
get_post_meta the field's value with which you want to update your Post title
wp_update_post the title with the above value

You must note that the parent post ID in this case will be the ID of the Post where you show the CRED, and this is stored in the CRED API $form_data['container_id'];

With this value you update the posts hidden field _wpcf_belongs_parent-post-slug_id

A good example is visible there:
http://pastebin.com/2BTbVbcs
https://toolset.com/forums/topic/register-for-event/page/2/#post-388619

Relevant Documentation:
https://toolset.com/documentation/user-guides/creating-cred-forms/
https://toolset.com/documentation/user-guides/cred-api/#csd
https://codex.wordpress.org/Child_Themes
https://codex.wordpress.org/Functions_File_Explained
https://codex.wordpress.org/WP_DEBUG

This support ticket is created vor 8 Jahre. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 19 Antworten, has 2 Stimmen.

Last updated by mirjanaM vor 8 Jahre.

Assisted by: Beda.

Author
Artikel
#388619

Sorry, mein Weekend kam dazwischen.

So, Ich hab mich mal umgeschaut.

1. Ich nehme an hier willst du der user sich "registrieren lassen":
hidden link

2. Dies Form (ID 10) beinhaltet KEIN nativer WordPress Post Titel.

[cred_field field='post_title' post='registrierung' value='' urlparam='']

Somit wird die CRED Form IMMER ein autodraft oder was auch immer generieren.
Ich verstehe, Du willst der Post Titel von dem Feld "[types field="produkt-titel"][/types]" herholen?
Aber dann MUSST Du immer noch irgendwelche infos da reinpacken.
Das heisst, wenn die Form ausgefüllt und abgeschickt wird, muss da immer noch was drinnen sein, damit wir das mit dem Code an den "echten" post Titel weitergeben können.

3. Wie auch immer, ich will hier nicht zu tief gehen, lass uns mal folgendes tun:

- Registrierung wird automatisch zum zugehörigen Produkt als Child zugewiesen
- registrant füllt der Titel selbst aus.

4. Ich hab dazu deine Form neu erschaffen. Bitte studiere sie genau.

5. Ich hab dazu folgender Code verwendet (wie empfohlen):

function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==10)
    {
        //get the Post ID of the current event:
       $event_id = $form_data['container_id'];
       //update the new registration post parent field with this ID:
       update_post_meta($post_id, '_wpcf_belongs_testprodukt_id', $event_id);   
    }
}
add_action('cred_save_data', 'my_save_data_action',10,2);

Dies funktioniert perfekt.

Bitte siehe den Post "Toolset test" dazu, ich hab ihn mit der CRED erschaffen

Wenn Du nun den Titel mit irgendwas anderem updaten willst, musst Du diese Data von irgendwoher haben. Feld, was auch immer.

Wenn Du dann den get_post_meta() und update_post_meta() verwendest den ich im zweiten Code empfehle kannst Du den Titel damit aktualisieren.

Lass mich wissen ob Du damit weitere Hilfe benötigst.

#388637
Edit Registrierung ‹ testme24 — WordPress.png

Hi Beda,

now it works. Title Auto update now.

With:

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']==45)
    {
        //get the Post ID of the current event:
       $testprodukt_id = $form_data['container_id'];
       //update the new registration post parent field with this ID:
       update_post_meta($post_id, '_wpcf_belongs_parent-post-type-slug_id', $testprodukt_id);
    }
}

and i figured out that with title...

[cred_generic_field field='post_title' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"generic_type":"post_title",
"default":"[wpv-post-title id="$testprodukt"]"
}
[/cred_generic_field]
</div>

-------------------

Now the Only problem left is....

How can i Assign User Fields to it, so I know witch User registers for it?

I tryed to make a Field Group and assign fields to it...but not worked.

(Screenshot)

this my code in CRED Form:

[php]
[credform class='cred-form cred-keep-original']

[cred_generic_field field='post_title' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"generic_type":"post_title",
"default":"[wpv-post-title id="$testprodukt"]"
}
[/cred_generic_field]


[cred_generic_field field='nickname' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"generic_type":"nickname",
"default":"[wpv-current-user id="$testprodukt"]"
}
[/cred_generic_field]


[cred_show_group if="($(nickname) eq  'anzeigename' )"  mode='fade-slide']
<div>Anzeigename: [cred_field field='anzeigename' post='registrierung' value='' urlparam='']</div>
[/cred_show_group]


[cred_generic_field field='first_name' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"generic_type":"first_name",
"default":"[wpv-current-user id="$testprodukt"]"
}
[/cred_generic_field]


[cred_show_group if="($(first_name) eq  'vorname' )"  mode='fade-slide']
<div>Vorname: [cred_field field='vorname' post='registrierung' value='' urlparam='']</div>
[/cred_show_group]


[cred_generic_field field='last_name' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"generic_type":"last_name",
"default":"[wpv-current-user id="$testprodukt"]"
}
[/cred_generic_field]


[cred_show_group if="($(last_name) eq  'name' )"  mode='fade-slide']
<div>Name: [cred_field field='name' post='registrierung' default='last_name' value='' urlparam='']</div>
[/cred_show_group]


[cred_generic_field field='regist' type='select' class='' urlparam='']
{
"required":1,
"validate_format":1,
"persist":1,
"default":["1"],
"options":[
{"value":"1","label":"Ja"},
{"value":"2","label":"nein"}
]
}
[/cred_generic_field]


[cred_field field='form_submit' value='Submit' urlparam='']

[cred_field field='form_messages' value='']

[/credform]
#388640

Sorry nicht gesehen das du schon gepostet hattes 🙂

Werde das gleich mal durch gehen...vielen Dank 🙂

#388653

Hallo Beda,

vielen Dank für deine Hilfe. Habe mir das nochmal genau angeschaut und verstehe es jetzt etwas besser.

Hoffe du hast noch nerven mir zu erklären wie ich noch den z.Bsp.: Usernamen des Aktuellen Userers in die Registrierung bekomme?

Schau mein Post (Screenshot..Code) https://toolset.com/forums/topic/register-for-event/page/2/#post-388637

Habe wie oben beschrieben versucht ein Type field mit einem User Field zu verbinden (generic_field) aber das war nichts 😉

Hoffe du hast da noch eine Idee oder lösung für mich.

Vielen Dank

Mira

#388701

Okay i resolved it by now.

Beda....
many thanks for your patience and help 🙂

Great work...THANK YOU

Mira

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.