Is it possible to press a button on a form and it takes the $_POST from the other form?

Asked

Viewed 40 times

0

I have a function that registers client

If the user presses the sign-up button the client will perform the function

If the user press the button to register phone, will perform the same function and then will register the phone of this customer.

I have a client record in a <form> and is going through $_POST and phone registration in another <form> also for $_POST

when I press the phone register, it registers the client then registers the phone but it does not pass the values of the first form, then all fields of the client are empty and all fields of phone filled

Note: if I put one form inside the other, the client registration button simply doesn’t work

  • Please put the codes here to facilitate our understanding.

  • You probably just need a FORM and client and phone to be INPUT fields within that single FORM,

  • 2

    You should not put one form inside the other, they should be separate. With the Forms separately, when you use the Ubmit button, the $_POST object will only have the fields from that form that you clicked on.

  • Each POST sent from a form Ubmit to the server form is responsible only for its data collection

  • Any alternative to this problem? what I need is a button register the client, the other button will serve to register phone, but if the user did not press the button to register the client, the same will register

1 answer

1


Put all the fields you want to register inside the same form:

Example:

<form action="/action_page.php" method="POST">
  Cliente:<br>
  <input type="text" name="cliente">
  <br>
  Telefone:<br>
  <input type="text" name="telefone">
  <br><br>
  <input type="submit" value="Submit">
</form> 



<?php
$cliente = $_POST['cliente'];
$telefone = $_POST['telefone'];
?>
  • 1

    You gave me a better idea, as I am doing the phone registration in a modal, put an if to say q if I am registering the customer modal is within the form of customer registration and if it is not will become two separate Forms, thank you very much

  • I got it for nothing !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.