简体   繁体   English

提交WPForm时用连字符替换空格

[英]Replace spaces with hyphens on submit of WPForm

In my WordPress site I have a WPForm submitting to a custom post type.在我的 WordPress 网站中,我有一个提交给自定义帖子类型的 WPForm。 In the notification that goes to the user, I want to generate the link for the post they just submitted, which comes from the title field in the form.在发给用户的通知中,我想为他们刚刚提交的帖子生成链接,该链接来自表单中的标题字段。

So if they submit a post titled "My Team Is Awesome", the email generates the link as因此,如果他们提交标题为“我的团队很棒”的帖子,则电子邮件会生成以下链接

<a href="https://example.com/my">https://example.com/my</a> team is awesome.

So as you can see, my problem is that if their title has more than one word, the blank spaces break the link that is generated.如您所见,我的问题是,如果他们的标题有多个单词,则空格会破坏生成的链接。 My site's permalink setting is to replace spaces with hyphens for posts, so how would I replace blank spaces in the title field and replace with hyphens as the WPForm is submitted?我网站的永久链接设置是用连字符替换帖子的空格,那么我将如何替换标题字段中的空格并在提交 WPForm 时用连字符替换? I've searched this specific to WPForm plugin and not finding anything.我已经针对 WPForm 插件搜索了这个,但没有找到任何东西。

You didn't post any code, or specific form structure in your question, so I can't give you a working code example, but as I understand it you're question is actually a combination of two separate questions I will try to answer:您没有在问题中发布任何代码或特定的表单结构,因此我无法为您提供工作代码示例,但据我了解,您的问题实际上是我将尝试回答的两个单独问题的组合:

1. How do I change a WPForm Field on form submission? 1. 如何更改表单提交时的 WPForm 字段?

Answer: You can use the wpforms_process_filter filter in functions.php to customize field values right after the form has been submitted, but before it is saved in the database and emails are sent.答:您可以使用wpforms_process_filter过滤器中functions.php自定义字段值的形式提交后的权利,但在此之前它被保存在数据库和电子邮件发送。

Detailed info here: https://wpforms.com/developers/wpforms_process_filter/详细信息在这里: https : //wpforms.com/developers/wpforms_process_filter/

2. How to I make a slug-like string out of a text string? 2. 如何从文本字符串中制作一个类似 slug 的字符串?

Use the native WordPress function sanitize_title() .使用原生 WordPress 函数sanitize_title()

Detailed info here: https://developer.wordpress.org/reference/functions/sanitize_title/详细信息在这里: https : //developer.wordpress.org/reference/functions/sanitize_title/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM