Start a conversation

Passing and retrieving variables by URL

On this tutorial we are going to create a form application witch uses a grid to automatically fill form's fields.
For that, the procedure of variable sending by URL, using array $_GET[] will be showed now.


1 - Creating Tables (MYSQL)
  • Tabel of people registering
CREATE TABLE cadastroPessoa(
ID INT NOT NULL AUTO_INCREMENT,
nome VARCHAR(20),
idade INT,
email VARCHAR(20),
cidade VARCHAR(20),
PRIMARY KEY( ID ))
  • Table of Sales Registering
CREATE TABLE cadastrovendas(
ID INT NOT NULL AUTO_INCREMENT,
nome VARCHAR(20),
email VARCHAR(20),
descricao VARCHAR(60),
valor FLOAT,
data DATE,
PRIMARY KEY( ID ),
)

2 - Creating and Configuring application
  • We are going to create a form application for CadastroVendas and a grid app for CadastroPessoa.
 
  • On grid app lets define the parameters which will be sent by URL.
    • Creating a field, "link", to use as link which redirect to form app with datas.
    • On the onRecord event we define the field {link} with form application's path concatenating with the variables that will be sent.
      {link} = "<a href='http://127.0.0.1:98/scriptcase/app/TESTES/form_cadastrovendas/form_cadastrovendas.php?nome=".{nome}."&email=".{email}."'>inserir</a>";
    • Check the final situation, that we've created th variables "nome", e "email"
  • On form's application let's create a virtual field to redirect to grid's application.
    • Creating a virtual field as Label, called "link"
    • On the onApplicationInit event we are going to use the macro sc_apl_conf(); to force the form to start with inclusion mode.
      sc_apl_conf('form_cadastrovendas','start','new');
    • On the onLoad event use the {link} to redirect to grid's application.
      {link} =  "<a href='http://127.0.0.1:98/scriptcase/app/TESTES/grid_cadastroPessoa/grid_cadastroPessoa.php'>Pesquisar</a>";
    • Still on onLoad event lets populate the fields with the variables sent by grid's URL.
      if(isset($_GET['nome']) && isset($_GET['email'])){
               {nome} = $_GET['nome'];
               {email} = $_GET['email'];
      }
 
3 - Running the application:
  • Run the form app. It is possible to see that the fields are blank . Click on "search".
  • When you've been redirected to grid's application choose one register to use, clicking on "Insert".
  • Check that the fields which were on blank situation, are now filled with chosen values.
Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Amanda Santos (Migrated deleted Agent)

  2. Posted
  3. Updated

Comments