How to use forms?

Game development with Board Game Arena Studio
Post Reply
Fred504
Posts: 22
Joined: 06 January 2024, 13:20

How to use forms?

Post by Fred504 »

Hello
I can't find in coinche example (of course, there's not in this game!) and in the documentation how to use forms?

How to make a form with a text field?

How to retrieve the text entered by the user?

Thanks for your help.
Last edited by Fred504 on 19 January 2024, 15:33, edited 1 time in total.
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: How to use forms?

Post by Victoria_La »

Are you player or developer? Have no idea what is corps... And if you cannot google "how to make form with a text field in html" you cannot move forward with development here...
Fred504
Posts: 22
Joined: 06 January 2024, 13:20

Re: How to use forms?

Post by Fred504 »

Victoria_La wrote: 19 January 2024, 01:12 Are you player or developer? Have no idea what is corps... And if you cannot google "how to make form with a text field in html" you cannot move forward with development here...
Forms not corps: sorry! Automatic spellchecking 😱

I know how to do forms and get the entered data with HTML/PHP!
I'm asking how to do it with BGA studio.

The place where the form is defined is in X_X.tpl as:

Code: Select all

{FORMINPUT}

In X.view.php, I have to set

Code: Select all

$this->tpl['FORMINPUT'] = ??? ;
Should I put the HTML code like

Code: Select all

<input type="text"...
How should I get the entered data?
With $_POST?
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: How to use forms?

Post by robinzig »

Fred504 wrote: 19 January 2024, 15:35 In X.view.php, I have to set

Code: Select all

$this->tpl['FORMINPUT'] = ??? ;
Should I put the HTML code like

Code: Select all

<input type="text"...
Why not just include the HTML in the tpl file? Unless of course it's not always on the page (which I assume it isn't), in which case you enter it dynamically in Javascript, either using the "JS template" blocks explained in the docs (https://en.doc.boardgamearena.com/Game_ ... _templates), or just directly using normal Javascript DOM methods.
How should I get the entered data?
With $_POST?
No, once a game is started the user interacts with the server via Ajax requests, not standard GET and POST requests. You probably want to add your own "submit" button and add an event listener to that to get the entered data and then do whatever you want with it.
Fred504
Posts: 22
Joined: 06 January 2024, 13:20

Re: How to use forms?

Post by Fred504 »

So, to say this is a form with input text, what should I write in

Code: Select all

$this->tpl['FORMINPUT'] = ??? 
What should I write to get text that thé player writes on thé form?
I can't find any explanation or example.
User avatar
Jonathan2004
Posts: 46
Joined: 21 April 2020, 19:06

Re: How to use forms?

Post by Jonathan2004 »

According to all your questions on the forum, you may have not read all the studio docs, which the entry is https://en.doc.boardgamearena.com/Studi ... I_start.3F.
And at least you should read AND code one of the tutorial.
Then you will see that every interactions from Client to Server is bound to asynchronous actions, so let's see the related page

The majority of games don't use text inputs, so you can check yourself the client code of those games (Concept, or Just One for example)

PS : It could be a good idea to play some games on BGA too, in order to get the idea of the players expectations.
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: How to use forms?

Post by robinzig »

Fred504 wrote: 22 January 2024, 15:11 So, to say this is a form with input text, what should I write in

Code: Select all

$this->tpl['FORMINPUT'] = ??? 
What should I write to get text that thé player writes on thé form?
I can't find any explanation or example.
What makes you think you have to do anything like that?

Putting variables into

Code: Select all

$this->tpl
is normally only useful/necessary to put translated text into your HTML template. So if you're giving a label to your form field (probably a good idea), you'll need to do this to ensure that label is translated into the user's language - but this, while important, does not seem to relate to your main question here.

To put a form somewhere on the page, simply insert it into the DOM, either via direct HTML output in the tpl file, or imperatively in your .js file when the appropriate game-state is reached. It's no different from inserting any other HTML elements in your interface.
Fred504
Posts: 22
Joined: 06 January 2024, 13:20

Re: How to use forms?

Post by Fred504 »

OK. Thanks! 👍
Last edited by Fred504 on 27 January 2024, 15:43, edited 2 times in total.
Fred504
Posts: 22
Joined: 06 January 2024, 13:20

Re: How to use forms?

Post by Fred504 »

Jonathan2004 wrote: 22 January 2024, 17:42 According to all your questions on the forum, you may have not read all the studio docs, which the entry is https://en.doc.boardgamearena.com/Studi ... I_start.3F.
And at least you should read AND code one of the tutorial.
Then you will see that every interactions from Client to Server is bound to asynchronous actions, so let's see the related page

The majority of games don't use text inputs, so you can check yourself the client code of those games (Concept, or Just One for example)

PS : It could be a good idea to play some games on BGA too, in order to get the idea of the players expectations.
I can't find the BGA codes of Decrypto and Just one on github.
Post Reply

Return to “Developers”