Creé un formulario como este, ¿cómo debo hacer para que el valor del campo del formulario se ingrese en la matriz de datos php?
Se espera que el valor de los datos enviados se ingrese en esta línea:
$customer_details = array( 'first_name' => "value input first_name", 'email' => "value input email", 'phone' => "value input phone" );entrada de formulario:
<form> <label>Name:</label> <input name="first_name" type="text" maxlength="50"><br> <label>Phone:</label> <input name="phone" type="text" maxlength="100"><br> <label>Email:</label> <input name="email" type="text" maxlength="100"><br><br> <button id="pay-button">Pay!</button> </form>El código php y el formulario html están en 1 archivo.
Su formulario necesita 2 atributos (acción, método) y su botón necesita 1 (tipo):
<form action="#" method="GET"> <label>Name:</label> <input name="first_name" type="text" maxlength="50"><br> <label>Phone:</label> <input name="phone" type="text" maxlength="100"><br> <label>Email:</label> <input name="email" type="text" maxlength="100"><br><br> <button type="submit" id="pay-button">Pay!</button> </form>Entonces, el botón Enviar manejará el formulario usando la misma página.
Puede verificar si el formulario se maneja usando esto:
if(isset($_GET['name'])) { //use your form }Entonces tienes una matriz existente $_GET . Puede acceder a sus datos usando el nombre de su entrada (por ejemplo: $_GET['first_name'] ).
Si desea utilizar su $customer_array , entonces:
$customer_details = array( 'first_name' => $_GET['first_name'], 'email' => $_GET['email'], 'phone' => $_GET['phone'] );ACTUALIZADO
El resultado final debe ser:
if(isset($_GET['name'])) { $customer_details = array( 'first_name' => $_GET['first_name'], 'email' => $_GET['email'], 'phone' => $_GET['phone'] ); //Any other treatment... } else { <form action="#" method="GET"> <label>Name:</label> <input name="first_name" type="text" maxlength="50"><br> <label>Phone:</label> <input name="phone" type="text" maxlength="100"><br> <label>Email:</label> <input name="email" type="text" maxlength="100"><br><br> <button type="submit" id="pay-button">Pay!</button> </form> }