Ich habe eine einfache HTML-Datei mit einem Formular, das den Benutzer nach bestimmten Informationen wie Name, Kontakt, Ort usw. fragt. Das Formular hat eine Aktion zu "send-sms.php", die eine Twilio-API verwendet, um eine SMS weiterzuleiten mein Telefon.Aufruf von Variablen aus HTML-Formular in PHP?
Der Text sendet ordnungsgemäß, aber die Art, wie ich versuche, die Variablen aus dem HTML-Formular aufzurufen, wird in meinem PHP-Code nicht erkannt. Mit anderen Worten, ich behalte den Text innerhalb der Anführungszeichen, aber nicht die Werte, die in die Eingabefelder übertragen wurden. Ich habe den Code unten enthalten:
<?php
require 'twilio-php-master/Services/Twilio.php';
$name = $_POST['name'];
$task = $_POST['task'];
$contact = $_POST['contact'];
$location = $_POST['location'];
$misc = $_POST['misc'];
$account_sid = 'AC*******************';
$auth_token = 'b********************';
$client = new Services_Twilio($account_sid, $auth_token);
$client->account->messages->create(array(
\t 'To' => "3177302557",
\t 'From' => "+13173644864",
\t 'Body' => "YOU GOT A NEW ERRAND, BET!: \n Name: $name \n Task: $task \n Contact: $contact \n Location: $location \n Misc: $misc",
));
?>
<form action="send-sms.php" method="POST">
<fieldset>
<legend><span class="number">1</span> Your Information</legend>
<input type="text" name="field1" id="name" placeholder="Your Name *">
<input type="email" name="field2" id="contact"placeholder="Contact Information (Email, Phone Number, etc.) *">
<input type="location" name="field3" id="location" placeholder="Your Location (i.e. McNutt, Hodge Hall, exact address, etc.)*">
<input type="text" name="field4" id="misc" placeholder="Miscellaneous Information That May Be Important"></textarea>
<label for="job">Urgency:</label>
<select id="job" name="field5">
<optgroup label="Urgency level: just for us to prioritize properly">
<option value="Not Urgent">Low (ETA: Up to an hour)</option>
<option value="reading">Normal (ETA: Up to 45 mins)</option>
<option value="boxing">Critical (ETA: ASAP!)</option>
</optgroup>
</select>
</fieldset>
<fieldset>
<legend><span class="number">2</span>Task that needs completion</legend>
<input type="text" id="task" name="field6" placeholder="Let Us Know How We Can Help!*"></input>
</fieldset>
<input name="submit" type="submit" value="Submit" onClick="push();validateForm();"/>
</form>
Ich bin überrascht, dass Sie überhaupt etwas bekommen. Sie haben Felder mit 'name =" fieldX' und greifen auf sie als '$ _POST ['name']' ... zu. – FirstOne