Skip Navigation

[Resolved] How to create a form that inputs multiple lines in body

This support ticket is created 5 years, 8 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 – 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)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 5 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#920948

Hi,

I'd like to have a form that creates a post. But instead of just a "Body" text field, I need it to have a way to input:

TITLE
TEXT

TITLE
TEXT

etc.

I would then pre-define these titles, which will later be pre-set to show up as h3 tages. And then the user text as a paragraph, such as:

<h3>Pre Set Title</h3>
<p>user input</P>

I was thinking I could use generic inputs? And then pull them with PHP hook and put all in the body. So later it all just seems like regular html coded into the body like any other post.

Does this make sense? Can you give me an example of how to approach the PHP part? Or if you have another suggestion on how to approach this I'd be open to another method.

THANKS!

#921138

Hello,

It is possible within repeatable field group:
https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/

In this case, you just need the post title and post body in the repeatable field group.

So your user can input different item, each item can have it's own post title and post body.

Then you will be able to setup a view to display items as what you want:
https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/#displaying-repeatable-field-groups
section "Displaying Repeatable Field Groups"

#923097

Hi,

Not quite what I asked for. But pursuing this approach further:

I don't see a way to add a repeatable group to CRED. On a google search through old posts all I see is a very convoluted system of creating child posts, etc, etc... very cumbersome and not at all useful.

Is there now, as of July 2018, a way to add repeatable groups to Cred forms (Yes, new name: post forms) or not? And is a method coming soon? Your documentation and blog notices are not very clear.

Thanks!

#923250

Yes, you are right, the repeatable field group is based on custom posts, each item of repeatable field group is a single post, but Toolset form (CRED) can create/edit only one post in each form, it can not create the multiple posts in one Toolset form.

So Toolset form does not support the repeatable group directly, you will need to creating child posts in another form.
I am not sure when this feature will be available, and I don't think a method is coming soon.

For your original question:
I was thinking I could use generic inputs? And then pull them with PHP hook and put all in the body. So later it all just seems like regular html coded into the body like any other post.

There isn't such a built-in feature within Toolset form plugin, it requires custom PHP codes:

Here is my opinion:
1) You can setup a custom multiple lines field, for example "my-field", ask users to input the content using specific format, for example:
TITLE
TEXT

TITLE
TEXT
...
each item with title and text is separated by a blank line,

2) After user submit the form, use CRED action hook cred_save_data to trigger a PHP function, in this function get the value of field "my-field", and use PHP codes to turn it to a PHP array, for example:
https://stackoverflow.com/questions/3012788/how-to-check-if-a-line-is-blank-using-regex

I have searched it in google, and found some similar threads:
hidden link

For your reference.

3) Then use wordpress function update_post_meta() to update the field value to what you want.
https://codex.wordpress.org/Function_Reference/update_post_meta

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