3
Form to send selected data for deletion.
<form action="index.php?pagina=../controller/controllerUser&acao=ok" method="POST" enctype="multipart/form-data">
<label>Nome:</label>
<input class="input-xlarge" type="text" value="<?php echo $nome; ?>" name="nome" autofocus=""> <br/>
<label>CPF:</label>
<input class="input-large" type="text" name="cpf" autofocus=""> <br/>
<label>Senha:</label>
<input class="input-large" type="text" name="senha" autofocus=""> <br/>
<label>Repetir a senha:</label>
<input class="input-large" type="text" name="confirmarSenha" autofocus=""> <br/>
<label>CEP:</label>
<input class="input-medium" type="text" name="cep" autofocus=""> <br/>
<label>Endereço</label>
<input class="input-xlarge" type="text" name="descricao" autofocus=""> <br/>
<label>Complemento</label>
<input class="input-xlarge" type="text" name="complemento" autofocus=""> <br/>
</div>
<div class="span6">
<label>E-mail</label>
<input class="input-xlarge" type="text" name="email" autofocus=""> <br/>
<label>Telefone</label>
<input class="input-xlarge" type="text" name="telefone" autofocus=""> <br/>
<label>Telefone Dois</label>
<input class="input-xlarge" type="text" name="telefoneDois" autofocus=""> <br/>
<label>Selecione um País</label>
<select required="" name="id_pais">
<?php
$daoPais->selecionaTodosPaises();
?>
</select>
<label>Selecione um estado</label>
<select required="" name="idEstado" id="idEstado" onchange="getValorEstado(this.value, 0)">
<option selected="" disabled="" value="nulo">Selecione o ESTADO</option>
<?php
$daoEstado->selecionaTodosEstados();
?>
</select>
<label>Selecione uma Cidade</label>
<select required="" id="idCidade" name="idCidade">
<option selected="" disabled="" value="nulo">Selecione o ESTADO ANTES</option>
<!-- chadamada de arquivo aqui com jquery utilizando
ajax, o arquivo se encontra uteis/selectCidade.php-->
</select>
<br></br>
<input class="btn btn-large btn-primary" type="submit" value="salvar">
<a class="btn btn-large btn-danger" href="index.php?pagina=PaginaResumo" value="Cancelar">Cancelar</a>
</form>
will redirect to the controller page you insert or delete so far.
if (isset($_GET["acao"]) and $_GET["acao"] == "ok") {
//primeiro inserir o endereço
//atributos de endereço
$descricao = $_POST["descricao"];
$complemento = $_POST["complemento"];
$cep = $_POST["cep"];
$idCidade = $_POST["idCidade"];
//objeto de endereco
$endereco = new EnderecoEntity("", $descricao, $complemento, $cep, $idCidade);
//dao de endereço
$daoEndereco = new EnderecoDao();
$idEndereco = $daoEndereco->inserirEndereco($endereco);
//depois inserir o usuário com id de endereço
$nome = $_POST["nome"];
$cpf = $_POST["cpf"];
$senha = $_POST["senha"];
$usuario = new UsuarioEntity("", $nome, $cpf, $senha, $idEndereco);
$usuarioDao = new UsuarioDao();
$idUsuario = $usuarioDao->inserirUsuario($usuario);
//depois inserir o telefone com id de usuário
$telefoneUm = $_POST["telefone"];
$telefoneDois = $_POST["telefoneDois"];
$telefone = new TelefoneEntity("", $telefoneUm, $telefoneDois, $idUsuario);
$telefoneDao = new TelefoneDao();
$telefoneDao->inserirTelefone($telefone);
//depois inserir email com id de usuário
$email = $_POST["email"];
$email = new EmailEntity("", $email, $idUsuario);
$emailDao = new EmailDao();
$emailDao->inserirEmail($email);
}
if (isset($_GET["acao"]) and $_GET["acao"] == "deletar") {
$idEndereco = $_GET["id_endereco"];
$idPessoa = $_GET["id"];
//verificação de confirmação do usuário
?>
<div class="alert alert-error">
//o ponto de erro é esse sei que vou perder os dados quando tentar retornar para esse form
<form action="index.php?pagina=../controller/controllerUser&acao=deletarConcluido"> method="POST" enctype="multipart/form-data">
<h4>Atenção!</h4>
Você realmente deseja excluir o usuário:
<?php
echo $_GET["nome"];
echo'<br/>';
echo ' <a class="btn btn-primary" href="index.php?pagina=PaginaResumo">Não</a>';
echo ' <input type="submit" class="btn btn-danger" value="SIM">';
?>
</form>
</div>
<?php
if(isset($_GET["acao"]) and $_GET["acao"] == "deletarConcluido") {
$idEndereco = $_GET["id_endereco"];
$idPessoa = $_GET["id"];
//Deletar email
$emailDao = new EmailDao();
$emailDao->deleteEmail($idPessoa);
//deletar telefone
$telefoneDao = new TelefoneDao();
$telefoneDao->deleteTelefone($idPessoa);
//Deletar usuario
$usuarioDao = new UsuarioDao();
$usuarioDao->deletePessoa($idPessoa);
//Deletar endereço
$enderecoDao = new EnderecoDao();
$enderecoDao->deleteEndereco($idEndereco);
}
}
Puts an Hidden field in the form.
– dm707
the problem is that are two different Forms, ie in one I have a table, and in the other only two buttons, if I pass a variable in this other it loses the previous values, is the mix of php without framework seems servelet.
– André Martins
I confess that I didn’t understand it very well, but why would I lose value if I added an Hidden field? It would just be added. You can only run one form at a time, so if you add Hidden to the form that will run, I see no problem. But edit the question and put these forms so I can understand better.
– dm707
I think the problem is logic, not form. Describe the case better.
– Papa Charlie
Make a delete confirmation for a job more suitable for php javascript, post the code of the two Forms.
– rray
the problem is that I would have to submit the other form, I believe that generating a variable in javascript and passing it could work
– André Martins
testei puts it in the controller form like this but it didn’t work <form action="index.php? page=.. /controller/controllerUser&acao=deletarConclude & idEndereco='. <? php echo $idEndereco ? >. '&idPessoa='. <? php echo $idPessoa? >. '" method="POST" enctype="Multipart/form-data">
– André Martins
I just did not understand why you do not create the boot delete inside this form? Ai instead of you use the get
– Andrei Coelho
@Andrei Coelho the functionality of delete is ok, what I need to do is make a confirmation in this form for really the user who wants to delete do this or simply give up and do not do this.
– André Martins
Got it. I think javascript solves it. I put the javascript tag in the tags to see if a professional appears in this language
– Andrei Coelho
@rray I just posted the code, some suggestion?
– André Martins
Is this form to create a record and delete? it will be used to make tbm changes?
– rray