Page 1 of 1

Pasar variable al .prg

PostPosted: Tue Aug 31, 2021 7:44 pm
by acuellar
Buenas estimados

Cómo se hace para pasar una variable al programa.prg desde el index.html
Code: Select all  Expand view

<a href="programa.prg">Pasa variable</a>
 


Gracias por la ayuda

Re: Pasar variable al .prg

PostPosted: Tue Aug 31, 2021 8:12 pm
by Otto
Adhemar, attached a sample.
Best regards,
Otto

Code: Select all  Expand view

function main
local cTest := "my Test"

TEMPLATE PARAMS cTest

<!DOCTYPE html>
<html>
<head>
    <style>
        body {background-color: powderblue;}
        h1   {color: blue;}
        p    {color: red;}
    </style>
</head>
<body>
   
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
   
    <a href="programa.prg">Pasa variable <?prg return cTest ?></a>
</body>
</html>

ENDTEXT

return

//----------------------------------------------------------------------------//
 

Re: Pasar variable al .prg

PostPosted: Tue Aug 31, 2021 9:20 pm
by acuellar
Thanks Otto

show me
Code: Select all  Expand view

This is a heading
This is a paragraph.

Pasa variable My test
 


And program.prg does not receive the variable

or as it is put in program.prg to receive it

I need to go to the same program from two buttons

Code: Select all  Expand view

 cTest="L"
<a href="program.prg">Muestra libres <?prg return cTest ?></a>
 cTest="O"
<a href="program.prg">Muestra ocupadas <?prg return cTest ?></a>

In Program.prg
  USE (  PATH_DATA+'base.dbf' ) SHARED NEW VIA 'DBFCDX'
  INDEX ON field->nombre TAG "nombre" FOR field->tipo=cTest MEMORY     

 

thanks for your time and help

Best regards,

Re: Pasar variable al .prg

PostPosted: Tue Aug 31, 2021 11:44 pm
by Otto
Adhemar, I think I misunderstood the question.
You mean you want to pass a variable from program.prg to another prg or the same?
Best regards,
Otto

Code: Select all  Expand view

function main
local cTest := "my Test"

TEMPLATE PARAMS cTest

<!DOCTYPE html>
<html>
<head>
   
</head>
<body>
   
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
   
   
    <a href="postpairs.prg?test=<?prg return cTest ?>">Pasa variable <?prg return cTest ?></a>
</body>
</html>

ENDTEXT

return

//----------------------------------------------------------------------------//


 


postpairs.prg


Code: Select all  Expand view


function Main()
 
? "--------------------------------------"
   ? "AP_FileName() --> cFileName   returns the filename.prg provided to Apache by the client"
   ? ValToChar(AP_FileName())
     
 
   ? "AP_GetPairs() --> Hash    returns a hash with all GET pairs, key and value "
   ? ValToChar(AP_GetPairs())
 
   ? "AP_Args() --> cArgs   returns the args provided to Apache by the client if any "
   ? ValToChar( AP_Args() )
 
   
? "--------------------------------------"
   
 

Re: Pasar variable al .prg

PostPosted: Tue Aug 31, 2021 11:50 pm
by Otto
Adhemar, or to the same page

program.prg

Code: Select all  Expand view


function main
local cTest := "my Test"
local cTest2 := "my Test lorem ipsum"

 
? "--------------------------------------"
   ? "AP_FileName() --> cFileName   returns the filename.prg provided to Apache by the client"
   ? ValToChar(AP_FileName())
     
 
   ? "AP_GetPairs() --> Hash    returns a hash with all GET pairs, key and value "
   ? ValToChar(AP_GetPairs())
 
   ? "AP_Args() --> cArgs   returns the args provided to Apache by the client if any "
   ? ValToChar( AP_Args() )
 
   
? "--------------------------------------"
   





TEMPLATE PARAMS cTest, cTest2

<!DOCTYPE html>
<html>
<head>
   
</head>
<body>
   
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
   
   
    <a href="program.prg?test=<?prg return cTest ?>">Pasa variable <?prg return cTest ?></a>
<br>
<a href="program.prg?test=<?prg return cTest2 ?>">Pasa variable <?prg return cTest2 ?></a>


</body>
</html>

ENDTEXT

return

//----------------------------------------------------------------------------//

 

Re: Pasar variable al .prg

PostPosted: Wed Sep 01, 2021 10:26 am
by Otto
Adhemar, I extended the sample to show POST and GET methods.

program1.prg

Code: Select all  Expand view


function main
    local cTest := "my Test"
    local cTest2 := "my Test lorem ipsum"


    ? "<HR>"
    ? "AP_Body()"
    ? AP_Body()
    ? "<HR>"

    ? "AP_Method()"
    ? AP_Method()
    ? "<HR>"

    ? "AP_UserIP() --> cUserIP  returns the IP, as string, of the client"
    ? AP_UserIP()

    ? "<HR>"
    ? "AP_HeadersIn() //--> Hash    returns a hash with all headers pairs, key and value"
    ? AP_HeadersIn()

    ? "<HR>"
    ? "AP_FileName() --> cFileName  returns the filename.prg provided to Apache by the client"
    ? ValToChar(AP_FileName())
    ? "<HR>"

    ? "AP_GetPairs() --> Hash   returns a hash with all GET pairs, key and value "
    ? ValToChar(AP_GetPairs())
    ? "<HR>"
    ? "AP_Args() --> cArgs  returns the args provided to Apache by the client if any "
    ? ValToChar( AP_Args() )
    ? "<HR>"
    ? "AP_PostPairs() --> Hash  returns a hash with all POST pairs, key and value"
    ? ( AP_PostPairs() )

    ? "<HR>"
    //AP_RPuts( uValue )    Sends a value, converted into a string, to the client. Returns nil
    AP_RPuts( "<H1>AP_RPUts test</H1><br>" )
    ? "<HR>"




TEMPLATE PARAMS cTest, cTest2

<!DOCTYPE html>
<html>
<head>
    <head>
        <meta charset="utf-8">
        <title>Meine Testseite</title>
    </head>
   
</head>
<body>
   
    <h1>Test  POST and GET</h1>
    <p>This is a test for POST and GET method</p>
   
    <h3>GET  method test</h3>
    <a href="program1.prg?test=<?prg return cTest ?>">Pasa variable - <?prg return cTest ?></a>
    <br>
    <a href="program1.prg?test=<?prg return cTest2 ?>">Pasa variable - <?prg return cTest2 ?></a>
    <br>

    <h3>POST method test - FORM</h3>
    <form action="program1.prg" method="post">
        User name:
        <br>
        <input type="text" name="username">
        <br>
        Password:
        <br>
        <input type="password" name="passw">
        <br><br>
        <input type="submit" value="Send data">
    </form>
</body>
</html>

ENDTEXT

return

//----------------------------------------------------------------------------//

 

Re: Pasar variable al .prg

PostPosted: Wed Sep 01, 2021 2:41 pm
by acuellar
Thanks very much Otto

I did it with AP_Args() usando Index.prg

now I'm going to deal with: Index.html

Thanks for your time and help

Re: Pasar variable al .prg

PostPosted: Wed Sep 01, 2021 8:23 pm
by Otto
Adhemar,

What do you want to do with index.html?

Best regards,
Otto

Re: Pasar variable al .prg

PostPosted: Wed Sep 01, 2021 10:55 pm
by acuellar
Dear Otto

I want to write: domain/folder and automatically run the index.prg

Don't write: domain/folder/index.prg

Thaknks for your help

Re: Pasar variable al .prg

PostPosted: Wed Sep 01, 2021 11:55 pm
by Otto

Re: Pasar variable al .prg

PostPosted: Thu Sep 02, 2021 4:39 am
by Antonio Linares
You have to create a .htaccess file with this content (thanks to Charly):

Code: Select all  Expand view
# --------------------------------------------------------------------------
# CONFIGURACION RUTAS PROGRAMA  (Relative to DOCUMENT_ROOT)
# --------------------------------------------------------------------------
SetEnv APP_TITLE            "MyApp v1.0a"


# --------------------------------------------------------------------------
# Impedir que lean los ficheros del directorio
# --------------------------------------------------------------------------
Options All -Indexes


# --------------------------------------------------------------------------
# Pagina por defectos
# --------------------------------------------------------------------------
DirectoryIndex index.prg main.prg

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.prg/$1 [L]
</IfModule>

Re: Pasar variable al .prg

PostPosted: Thu Sep 02, 2021 11:21 am
by acuellar
Perfecto.
Muchas gracias Antonio
Thanks Otto

Es un poco complicadito entenderle la lógica de la programación Web.
Pero ya estamos impulsado y lo lograremos :D


Gracias por su tiempo y ayuda.