(6) GET and POST:-
we will talk about :-
  • What is GET and POST Methods ?
  • How to use GET Method ?
  • How to use POST Method ?

I will explain to you what and how to use GET and POST in Dragon-FramWork


Note:-

We have two Methods

  • (1) GET .
  • (2) POST .


(1)What is GET and POST Methods ?

The (GET) and (POST) Methods is methods that you can use in forms ...
The GET method can be used for the normal information because it is not secure ...

How to use GET Method ?
Example :-
In the route.ring we have this code
#!ring -cgi 
load 'dragon-ring.ring'
import system.Web
app.route('testget',:ringfile,'testget.ring')

In the website/testget.ring we have this code :
import system.web
dring{
  html(template('testget.html',self))
}

In the website/templates/testget.html we have this code
<form method='GET' >
    <input name='mytext' />
    <button name='btn'>Click Me</button>
</form>

When we write any thing and click on the button we will show something like this in the 'URL'

http://localhost/testget?mytext=testing+get&btn=Submit


How to use POST Method ?

It is more simple and secure than GET method


Example :-
In the route.ring we have this code
#!ring -cgi 
load 'dragon-ring.ring'
import system.Web
app.route('testpost',:ringfile,'testpost.ring')

In the website/testpost.ring we have this code :
import system.web
dring{
    html(template('testpost.html',self))
}

In the website/templates/testpost.html we have this code
<form method='POST' >
    <input name='mytext' />
    <button name='btn'>Click Me</button>
    {%=btn([:name='Click Me 2' , :href='testpost' ])%}
</form>

When we write any thing and click on the button we will show something like this

http://localhost/testpost
btn(alist) function :- this function can be used with post and get but you have to use it with POST because there is no another way ...
You can not write something like this:-
<form method='POST' >
    <input name='mytext' />
    <button name='btn'>Click Me</button>
</form>
It will not work !!
the correct way is use this function instead of <button> tag ...
it takes list contain :-
  • btn([:name]) :- the name and value of the button{%=btn([:name='mybtn'])%}
  • btn([:href]) :- the page route that you want to POST the information to . {%=btn([:href='testpost',:name='mybtn'])%}
  • btn([:class] :- The class name (also you can use bootstrap classes))
  • btn([:style]) :- The css code and style .{%=btn([:style='background-color:red;'])%}

I hope it was easy for you ...