Skip to content

Instantly share code, notes, and snippets.

@varlen
Last active August 28, 2017 13:07
Show Gist options
  • Save varlen/c593dea4dfbd65b1cb7d4b80f522a496 to your computer and use it in GitHub Desktop.
Save varlen/c593dea4dfbd65b1cb7d4b80f522a496 to your computer and use it in GitHub Desktop.
Exemplos para o Minicurso de Desenvolvimento Web
<?php
/**
* Formulário simples utilizando método POST
*/
?>
<!DOCTYPE html>
<html>
<head>
<title>Minha Página</title>
<meta charset="UTF-8">
</head>
<body>
<?
if ($_POST['nome'])
{
?>
<h1> Olá,
<? echo $_POST['nome']; ?>
</h1>
<?
}
?>
<form action="/" method="POST">
<label for="nome">Digite seu nome</label>
<input type="text" name="nome" />
<input type="submit" value="Enviar" />
</form>
</body>
</html>
<?php
/**
* Sessão
*/
session_start();
if (! $_SESSION['todoList'])
{
$_SESSION['todoList'] = array();
}
if ($_POST['remove'] != "")
{
unset($_SESSION['todoList'][ $_POST['remove'] ]);
}
else if ($_POST['item'] != "")
{
array_push($_SESSION['todoList'], $_POST['item']);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Minha Lista</title>
<script
src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g="
crossorigin="anonymous"></script>
<meta charset="UTF-8">
</head>
<body>
<h4> Lista de Tarefas </h4>
<ul>
<? foreach ($_SESSION['todoList'] as $key => $value)
{
?><li data-id="<? echo $key ?>"><? echo $value; ?></li><?
}
?>
</ul>
<form action="/" method="POST">
<input placeholder="Novo item..." type="text" name="item" />
<input type="hidden" name="remove" />
<input type="submit" value="+" />
</form>
<script>
$(document).ready(function () {
$("li[data-id]").click(function (evt) {
var id = $(evt.target).data("id");
$("input[name='remove']").val(id);
$("form").submit();
});
});
</script>
</body>
</html>
<?php
/**
* Sessão
*/
session_start();
if (! $_SESSION['todoList'])
{
$_SESSION['todoList'] = array();
}
if ($_POST['remove'] != "")
{
//array_splice($_SESSION['todoList'], $_POST['remove']);
}
else if ($_POST['item'] != "")
{
array_push($_SESSION['todoList'], $_POST['item']);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Minha Lista</title>
</head>
<body>
<h4> Lista de Tarefas </h4>
<ul>
<? foreach ($_SESSION['todoList'] as $key => $value)
{
?><li data-id="<? echo $key ?>"><? echo $value; ?></li><?
}
?>
</ul>
<form action="/" method="POST">
<input placeholder="Novo item..." type="text" name="item" />
<input type="hidden" name="remove" />
<input type="submit" value="Enviar" />
</form>
</body>
</html>
<?php
/**
* Tabela
*/
$dados = [
["Igor", "121212121"],
["Varlen", "123123123"],
["Carla", "124123122"]
];
?>
<!DOCTYPE html>
<html>
<head>
<title>Minha Página</title>
<meta charset="UTF-8">
</head>
<body>
<table>
<thead>
<td>Nome</td>
<td>DRE</td>
</thead>
<?
foreach($dados as $linha)
{
?>
<tr>
<td><? echo $linha[0]; ?></td>
<td><? echo $linha[1]; ?></td>
</tr>
<?
}
?>
</table>
<style type="text/css">
table, td {
border: solid 1px;
}
</style>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment