Page 1 of 1

How to use forms?

Posted: 18 January 2024, 20:21
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.

Re: How to use forms?

Posted: 19 January 2024, 01:12
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...

Re: How to use forms?

Posted: 19 January 2024, 15:35
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?

Re: How to use forms?

Posted: 20 January 2024, 01:12
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.

Re: How to use forms?

Posted: 22 January 2024, 15:11
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.

Re: How to use forms?

Posted: 22 January 2024, 17:42
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.

Re: How to use forms?

Posted: 23 January 2024, 01:22
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.

Re: How to use forms?

Posted: 27 January 2024, 14:44
by Fred504
OK. Thanks! 👍

Re: How to use forms?

Posted: 27 January 2024, 14:46
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.