3. Passing Data from a Form

Passing data from a form and retrieving it using WebDNA

Now let's interact with WebDNA: send it some data, some instructions, and see WebDNA process it.

To do this, you will need two pages: one that sends the data, the other one that processes the data. (You could even do this using a single page: it would send the data to itself, and process it based on certain conditions. But let's work with two pages here.)

In html, if you want to send data to a server, you use a form to POST or GET data. What is the difference? GET is the "old way": the data appears in your URL, which could be a little bit dangerous nowadays, and your limit is 256 characters. POST doesn't show anything and has no limit, so we will use POST. (Both ways are accepted by WebDNA).

Let's build a basic form that sends anything you want, using simple html:
<html>
<form method="post" action="formprocess.dna">
<input type="text" name="data" size="30">
</br>
<input type="submit">
</form>
</html>

This cannot be simpler :-) Let's see the formprocess.dna now:

Make sure your page starts with <!--HAS_WEBDNA_TAGS--> and then, we will recover the data. What was the name of the field passing the data? "data"

So, to recover your data, just do this:
<!--HAS_WEBDNA_TAGS-->
[data]

Write anything you want in the form, submit, and you will see the second page, formprocess.dna, with what you wrote. Pretty simple, huh?

Now, let's imagine you want to do something with the data; for instance, show a personal message to Chris and just say hello to anybody else:
<!--HAS_WEBDNA_TAGS-->
[showif [data]=chris]Hi Chris? did you buy the milk?[/showif]
[hideif [data]=chris]Hello there![/hideif]

Let's do some math: write 4 plus 23 in the form, and
<!--HAS_WEBDNA_TAGS-->
[math][data][/math]

in formprocess.dna, it will return "27"

And what if your data is an email address that would send a specific email to the registered user? The subject will be "Thank you" and the message "Thank you for registering! Today is 05/24/2019"
Make your formprocess.dna like this:
<!--HAS_WEBDNA_TAGS-->
[SendMail to=[data]&from=me@mydomain.com&subject=Thank you]
Thank you for registering! today is [date]
[/SendMail]


image
>>> Next page... Christophe Billiottet

DOWNLOAD WEBDNA NOW!

Top Articles:

Related Readings:

2. Conditional Programming

Conditional programming with WebDNA...

5. Writing Files

How to write a file using WebDNA...

7. Searching Databases

Searching databases with WebDNA and conclusion...

3. Passing Data from a Form

Passing data from a form and retrieving it using WebDNA...

Kendo UI

This is a Code Library built with WebDNA...

6. Working with Databases

Working with WebDNA database...