-1

I need to use the method POST and GET at the same time. The "post" to submit and save the infos present on the inputs and GET to redirect the user by the other part of the code. I've read that it isn't possible, so, I thought that using JS to submit the form would be a good choice, but I don't know anything about JS, how is it possible to be done?

EDIT* I'm want to use both (GET and POST) due the selector that contains the complement of my redirect header, take a look: header ("Location: https://mpago.la/".$_GET['qtd']);

It uses GET to take the value of the selected item, add it to the url that is set on the header and redirect the user to the final url.

I've tried to change the method on the forms to post, but it didn't work, it only redirect to the firts part of the url, but I need it to redirect to the complete url.

'''

<?php 
include('conexao.php')
?>
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Comprar</title> 
<link rel="stylesheet" href="index.css">
</head>
<body>
<form action="processa.php" method="POST" class="u-clearfix u-form-spacing-10 u-form-vertical u-inner-form" source="customphp" name="form" style="padding: 10px;">
            <div class="u-form-group u-form-name u-form-partition-factor-3">
    <label for="name-7f1d" class="u-custom-font u-font-montserrat u-label">Nome</label>
              <input type="text" placeholder="Nome" id="name-7f1d" name="nome" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-1" required="">
            </div>
            <div class="u-form-group u-form-partition-factor-3 u-form-group-2">
              <label for="text-0791" class="u-custom-font u-font-montserrat u-label">Sobrenome</label>
              <input type="text" placeholder="Sobrenome" id="text-0791" name="sobrenome" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-2" required="required">
            </div>
            <div class="u-form-date u-form-group u-form-partition-factor-3 u-form-group-3">
              <label for="date-fccf" class="u-custom-font u-font-montserrat u-label">Data de nascimento</label>
              <input type="date" placeholder="MM/DD/YYYY" id="date-fccf" name="data_nascimento" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-3" required="">
            </div>
            <div class="u-form-group u-form-partition-factor-3 u-form-group-4">
              <label for="text-47b0" class="u-custom-font u-font-montserrat u-label">CPF</label>
              <input type="text" placeholder="CPF" id="text-47b0" name="cpf" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-4" required="required">
            </div>
            <div class="u-form-email u-form-group u-form-partition-factor-3">
              <label for="email-7f1d" class="u-custom-font u-font-montserrat u-label">Email</label>
              <input type="email" placeholder="E-mail" id="email-7f1d" name="email" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-5" required="">
            </div>
            <div class="u-form-group u-form-partition-factor-3 u-form-group-6">
              <label for="text-1865" class="u-custom-font u-font-montserrat u-label">Celular com DDD</label>
              <input type="text" placeholder="DDD + Celular" id="text-1865" name="numero_celular" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-6" required="required">
            </div>
            <div class="u-form-group u-form-partition-factor-3 u-form-group-7">
              <label for="text-44d8" class="u-custom-font u-font-montserrat u-label">Instagram</label>
              <input type="text" placeholder="Instagram" id="text-44d8" name="instagram" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-7" required="required">
            </div>
            <div class="u-form-group u-form-partition-factor-3 u-form-select u-form-group-8">
              <label for="select-0a03" class="u-custom-font u-font-montserrat u-label">Estado</label>
              <div class="u-form-select-wrapper">
                <select id="select-0a03" name="estado" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-8" required="required">
                  <option value="AC - Acre">AC - Acre</option>
                  <option value="AL - Alagoas">AL - Alagoas</option>
                  <option value="AP - Amapá">AP - Amapá</option>
                  <option value="AM - Amazonas">AM - Amazonas</option>
                  <option value="BA - Bahia">BA - Bahia</option>
                  <option value="CE - Ceara">CE - Ceara</option>
                  <option value="DF - Distrito Federal">DF - Distrito Federal</option>
                  <option value="ES - Espírito Santo">ES - Espírito Santo</option>
                  <option value="GO - Goiás">GO - Goiás</option>
                  <option value="MA - Maranhão">MA - Maranhão</option>
                  <option value="MT - Mato Grosso">MT - Mato Grosso</option>
                  <option value="MS - Mato Grosso do Sul">MS - Mato Grosso do Sul</option>
                  <option value="MG - Minas Gerais">MG - Minas Gerais</option>
                  <option value="PA - Pará">PA - Pará</option>
                  <option value="PB - Paraíba">PB - Paraíba</option>
                  <option value="PR - Paraná">PR - Paraná</option>
                  <option value="PE - Pernambuco">PE - Pernambuco</option>
                  <option value="PI - Piauí">PI - Piauí</option>
                  <option value="RJ - Rio de Janeiro">RJ - Rio de Janeiro</option>
                  <option value="RN -  Rio Grande do Norte">RN -  Rio Grande do Norte</option>
                  <option value="RS - Rio Grande do Sul">RS - Rio Grande do Sul</option>
                  <option value="RO - Rondônia">RO - Rondônia</option>
                  <option value="RR - Roraima">RR - Roraima</option>
                  <option value="SC - Santa Catarina">SC - Santa Catarina</option>
                  <option value="SP - São Paulo">SP - São Paulo</option>
                  <option value="SE - Sergipe">SE - Sergipe</option>
                  <option value="TO - Tocantins">TO - Tocantins</option>
                </select>
                <svg xmlns="http://www.w3.org/2000/svg" width="14" height="12" version="1" class="u-caret"><path fill="currentColor" d="M4 8L0 4h8z"></path></svg>
              </div>
            </div>
            <div class="u-form-group u-form-partition-factor-3 u-form-group-9">
              <label for="text-3838" class="u-custom-font u-font-montserrat u-label">Cidade</label>
              <input type="text" placeholder="Cidade" id="text-3838" name="cidade" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-9" required="required">
            </div>
            <div class="u-form-group u-form-partition-factor-5 u-form-group-10">
              <label for="text-bdfe" class="u-custom-font u-font-montserrat u-label">Bairro</label>
              <input type="text" placeholder="Bairro" id="text-bdfe" name="bairro" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-10" required="required">
            </div>
            <div class="u-form-group u-form-partition-factor-5 u-form-group-11">
              <label for="text-4102" class="u-custom-font u-font-montserrat u-label">CEP</label>
              <input type="text" placeholder="CEP" id="text-4102" name="cep" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-11" required="required">
            </div>
            <div class="u-form-group u-form-partition-factor-5 u-form-group-12">
              <label for="text-8b8c" class="u-custom-font u-font-montserrat u-label">Nome da Rua</label>
              <input type="text" placeholder="Nome da rua" id="text-8b8c" name="nome_rua" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-12" required="required">
            </div>
            <div class="u-form-group u-form-partition-factor-5 u-form-group-13">
              <label for="text-be7c" class="u-custom-font u-font-montserrat u-label">Número</label>
              <input type="text" placeholder="Número" id="text-be7c" name="numero" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-13" required="required">
            </div>
            <div class="u-form-group u-form-partition-factor-5 u-form-group-14">
              <label for="text-6e58" class="u-custom-font u-font-montserrat u-label">Complemento</label>
              <input type="text" placeholder="Complemento" id="text-6e58" name="complemento" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-14" required="required">
            </div>
            <div class="u-form-group u-form-select u-form-group-15">
              <label for="select-45ba" class="u-custom-font u-font-montserrat u-label">Quantidade de Números</label>
              <div class="u-form-select-wrapper">
                <select id="qtd" name="qtd" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-15" required="required">
                  <option value="QTD">QTD</option>
                  <option value="21krWeb">1 - R$32</option>
                  <option value="1XJSsx8">2 - R$64</option>
                  <option value="3 - R$96">3 - R$96</option>
                  <option value="4 - R$128">4 - R$128</option>
                  <option value="5 - R$160">5 - R$160</option>
                  <option value="10 - R$312">10 - R$312</option>
                  <option value="20 - R$632">20 - R$632</option>
                  <option value="25 - R$792">25 - R$792</option>
                </select>
                <svg xmlns="http://www.w3.org/2000/svg" width="14" height="12" version="1" class="u-caret"><path fill="currentColor" d="M4 8L0 4h8z"></path></svg>
              </div>
            </div>
            <div class="u-align-center u-form-group u-form-submit">
              <a href="#" class="u-border-none u-btn u-btn-round u-btn-submit u-button-style u-custom-color-3 u-radius-50 u-btn-1">Enviar</a>
              <input type="submit" value="submit" class="u-form-control-hidden">
            </div>
            <input type="hidden" value="" name="recaptchaResponse">
          </form>
</body>
'''
Antoniazi
  • 23
  • 2
  • That is not possible. Why are you not posting the form to the server and having the PHP code do the redirect? https://stackoverflow.com/questions/768431/how-do-i-make-a-redirect-in-php – epascarello Nov 08 '22 at 17:03
  • I've edited the post and added some aditional info, now I think it explains what I need to do. – Antoniazi Nov 08 '22 at 17:36
  • 1
    "EDIT* I'm want to use both (GET and POST) due the selector that contains the complement of my redirect header, take a look: `header ("Location: https://mpago.la/".$_GET['qtd']);"` — Don't do that. Use `$_POST` on the server instead. – Quentin Nov 08 '22 at 17:38
  • 1
    Not sure if I do understand you correct, but you could put your GET values into form action like: `action="processa.php?getvalue1=a&b=c"`. Probably you might need some Javascript to modify the form action as it appears to be dynamic and not to be statically defined or with PHP $variables. – Tim Nikischin Nov 08 '22 at 17:42
  • Guys, it worked, I've changed the method used on the header to $_POST and it worked, now the user is redirected to the complete url – Antoniazi Nov 08 '22 at 18:17

1 Answers1

1

You might be better submitting the form via POST as you are doing and then in the PHP you could use a header('Location: http://www.example.com/'); to redirect the user to the page you want after the form is processed.

https://www.php.net/manual/en/function.header.php

I am not sure why you would want to both POST and GET as they are both used to submit data so I would assume the POST would handle that and hopefully the redirect option works for you to get the user to the next stage.