דוגמה לתוסף עם טופס בבקשת POST

Hello All!

We are working to try and unblock a plugin development we are doing here in Error "Unable to configure link to 'Auto Send Messages'. Ensure ad-blockers are disabled and try reloading the page."

And we we could really use a working example of a plugin that has a form submission type action built into it. Our plugin has two things, at a high level:

  • some configuration items
  • a form that a user would input some text into, and then ‘submit’ to process

So if anyone knows of any plugin that has these two types of features, we would really appreciate a link to it so we can review how it works.

Thank you!

Can you say more about what you’re doing? What are you changing with the form? Can this be a theme component? Is what you’re submitting to an existing endpoint or one that you’re adding?

See Discourse toolkit to render forms

Then you can get GitHub - discourse/all-the-plugins and grep for “<Form” but you can also see Code search results · GitHub as described in Discourse toolkit to render forms - #20 by david (though those are all in core, not plugins)

Maybe see discourse-data-explorer/assets/javascripts/discourse/components/param-input-form.gjs at main · discourse/discourse-data-explorer · GitHub

2 לייקים

FormKit is pretty new.

I’ve not even updated Locations plugin to use it yet.

(But it’s definitely the right thing to use if starting anew :+1:)

לייק 1

[ציטוט=“רוברט, הודעה:3, נושא:351930, שם משתמש:merefield”]
FormKit די חדש.
[/ציטוט]

זה כל כך נכון. זה עדיין מה שהייתי ממליץ עליהם למי שכותב קוד חדש.

[ציטוט=“רוברט, הודעה:3, נושא:351930, שם משתמש:merefield”]
אני אפילו לא עדכנתי את תוסף המיקומים כדי להשתמש בו עדיין.
[/ציטוט]

שימושי בו עבור משהו חדש שאני עובד עליו. (ואתה יכול לראות אותי מתלונן על זה הרבה בפורום על זה!)

2 לייקים

@pfaffman We want to create a simple form that prompts the user for four things:

  1. Sender
  2. Receiver
  3. Subject
  4. Body

The user will fill out these fields, and then click a button to trigger an endpoint that sends the email.

Specifically, the form will include the four elements, and once the “Send” button is clicked, it will invoke the endpoint to send the message.

I’m not sure if that’s exactly what you’re looking for, but the main goal is to allow an admin user to input text (the email subject and body) and click a button to send it to a user in Discourse.

In the future, we’d like to extend this so that the user can trigger multiple messages from one sender to multiple receivers. We want to manipulate parameters like the total number of messages and the delay between each one, to control how many messages are sent and how spaced out they are.

Maybe back up one step further and describe the actual problem you’re trying to solve.

Do you mean that you want to send a direct email (so the message will not exist in Discourse), or that you want to send a PM that goes to the user (which in most cases will generate an email notification).

You want to change who the sender of the PM is? That seems like the only thing that’s missing from the existing PM interface, is that right?

לייק 1

תודה על ההבהרה! כדי לספק עוד הקשר, אנחנו עובדים עם בסיס משתמשים גדול ורוצים להחזיר את המשתמשים שלא התקשו עם האפליקציה שלנו לזמן מה. המטרה היא לשלוח הודעה פרטית (PM) למספר גדול של משתמשים מכתובת שולח ספציפית, עם שליטה על מספר פרמטרים:

  1. שולח: משתמש המנהל יפריד את שם המשתמש של השולח ישירות בטופס.
  2. נושא  תוכן ההודעה: המנהל יכול להתאים אישית את הנושא ואת גוף ההודעה.
  3. שליטה על נפח ההודעות: אנו רוצים לשלוט כמה הודעות נשלחות בו זמנית כדי להימנע מספאם.
  4. זמנון: הדאגה המרכזית היא לוודא שאנו יכולים לשלוט על מהירות השליחה, כדי למנוע עומס על הדומיין שלנו ולמנוע סימון כהודעת ספאם. נצטרך לאפשר הפרדת ההודעות באמצעות הגדרת עיכובים בין כל הודעה (והדואר האלקטרוני המתאים) כדי למנוע זיהוי אוטומטי של ספאם.

המטרה הסופית היא לגרום למשתמשים לפתוח את ההודעה הפרטית (שגם תיצור התראה בדואר אלקטרוני) ולעודד אותם לחזור לאפליקציה שלנו.

יש לנו כבר סקריפט רובי פשוט שמסוגל לבצע משימה זו ועובד באופן מושלם. כרגע, אנחנו מפעילים אותו ידנית על ידי גישה לשרת הווירטאלי באמצעות SSH, שזה קצת מסורבל. מה שאנו רוצים עכשיו הוא להתאים את הסקריפט הזה לתוסף כך שמנהל יוכל להפעיל אותו בקלות דרך ממשק המשתמש, עם אפשרות להזין את ההגדרות (שולח, נושא, גוף ההודעה, כמות ההודעות, עיכוב ביניהן וכו’) ישירות מממשק המנהל.

אנחנו רוצים להשיג זאת באמצעות ממשק תוסף שמאפשר למנהל להזין בקלות את ההגדרות, להפעיל את התהליך ולפקח על התקדמות השליחה של ההודעות.

לייק 1

זה הרבה חתיכות.

כנראה שהיית עושה משהו כמו שיש קבוצות של משתמשים ומתכנן לשלוח לכל המשתמשים בקבוצה. כאשר נשלחת הודעה, תגדיר ערך בשדה מותאם אישית של המשתמש (user_custom_field) ותשתמש בנושא קיים כטקסט וכשולח ההודעה. משימה תוריץ כל הזמן ותשלח את הכמות ההודעות שתרצה. הייתי מחיל את הקבוצה ואת הערך של השדה המותאם בהגדרות.

אז לא היית צריך ממשק משתמש או ליצור נתיב חדש בכלל; היית יכול פשוט להשתמש בהגדרות קיימות. וגם, היית יכול לראות מה קרה באמצעות קונטרולר הנתונים, כך שלא היית צריך לפתח ממשק גם כן.

אם אתה רוצה ליצור שדות שהמשתמשים ייכנסו אליהם ב-UX, כדאי שתריץ את ה-<Form> שציינתי כבר.

לייק 1