2016-07-14 24 views
-1

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>

+1

Ich bin überrascht, dass Sie überhaupt etwas bekommen. Sie haben Felder mit 'name =" fieldX' und greifen auf sie als '$ _POST ['name']' ... zu. – FirstOne

Antwort

2

id Attribute in Formularfelder sind NICHT für Formularübermittlung verwendet. nur name ist:

<input type="text" name="field1" id="name" placeholder="Your Name *"> 
          ^^^^^---used for form submission 

$foo = $_POST['name']; // warning: undefined index 
$foo = $_POST['field1']; // A-OK 

Wenn Sie sogar BASIC Debuggen getan hatte, wie var_dump($_POST); Sie Ihren Fehler gesehen haben würde.