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:
<form method="post" action="formprocess.dna">
<input type="text" name="data" size="30">
<input type="submit">

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:

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:
[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

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 10/26/2021"
Make your formprocess.dna like this:
[SendMail to=[data]&from=me@mydomain.com&subject=Thank you]
Thank you for registering! today is [date]

>>> Next page... Christophe Billiottet


Top Articles:

Related Readings:

6. Working with Databases

Working with WebDNA database...

WebDNACodeSparker FRAMEWORK by Govinda

I am glad to help the beginners...

3. Passing Data from a Form

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

1. Learn WebDNA Programming

Learning WebDNA programming: the very basics...

Kendo UI

This is a Code Library built with WebDNA...

2. Conditional Programming

Conditional programming with WebDNA...