0

以前にこの質問を投稿したことがありますが、うまくいきませんでした。誰か助けてください。

私は機能しているキャプチャフォームを持っていますが、一度に1つずつ送信する複数選択を許可するように設定されたリスト/メニューを送信できないようです.PHPに追加するコードがわかりません.

(Benjamin Oman) の助けを借りましたが、フォームは実際の主要領域ではなく、Array という単語のみを送信します。

これは彼が提案したものです:

形:

<select name="main_area[]" size="1" multiple="multiple">
<option value="Durban">Durban</option>
<option value="South Coast">South Coast</option>
</select>

PHP:

echo "Main Area(s): \"" . print_r($_POST["main_area"], true) . "\" <br>";

これは私のphpです:

<?

session_start();

// *** We need to make sure theyre coming from a posted form -
//    If not, quit now ***
if ($_SERVER["REQUEST_METHOD"] <> "POST")
die("You can only reach this page by posting from the enquiry form");

// *** The text input will come in through the variable $_POST["captcha_input"],
//    while the correct answer is stored in the cookie $_COOKIE["pass"] ***
if ($_POST["captcha_input"] == $_SESSION["pass"])
{
// *** They passed the test! ***
// *** This is where you would post a comment to your database, etc ***
echo "<h2><span>Thank</span> You</h2>";
echo "Correct! You have entered the correct code. <br><br>";
echo "Your enquiry has been sent <br><br>";

echo "Overview of the information you have sent  <br><br>";

echo "Onditions of contract: \"" . $_POST["onditions_of_contract"] . "\" <br>";

echo "Tender results: \"" . $_POST["tender_results"] . "\" <br>";

echo "Resume: \"" . $_POST["resume"] . "\" <br>";

echo "Commodities: \"" . $_POST["commodities"] . "\" <br>"; // *** multiple select ***

echo "Main Area: \"" . $_POST["main_area"] . "\" <br>"; // *** multiple select ***

echo "Sub Area: \"" . $_POST["sub_area"] . "\" <br>"; // *** multiple select ***

echo "Company: \"" . $_POST["company"] . "\" <br>";

echo "Company Vat Number: \"" . $_POST["company_vat_number"] . "\" <br>";

echo "Reg. Number: \"" . $_POST["reg_number"] . "\" <br>";

echo "E-mail Address: \"" . $_POST["email_address"] . "\" <br>";

echo "Correspondence Address: \"" . $_POST["correspondence_address"] . "\" <br>";

echo "Street Address: \"" . $_POST["street_address"] . "\" <br>";

echo "For Attention Of: \"" . $_POST["for_attention_of"] . "\" <br>";

echo "Telephone Number: \"" . $_POST["telephone_number"] . "\" <br>";

echo "Fax Number: \"" . $_POST["fax_number"] . "\" <br>";


//sends email via php to the following address
$mailuser = "my@email.com";

//echo 'default chosen address: '.$mailuser;

$header = "Return-Path: ".$mailuser."\r\n"; 
$header .= "From: Security Form <".$mailuser.">\r\n"; 
$header .= "Content-Type: text/html;"; 

$mail_body = '
Onditions of contract: '. $_POST[onditions_of_contract] . '<br>
Tender results: '. $_POST[tender_results] . '<br>
Resume: '. $_POST[resume] . '<br>
Commodities: '. $_POST[commodities] . '<br>
Main Area: '. $_POST[main_area] . '<br>
Sub Area: '. $_POST[sub_area] . '<br>
Company: '. $_POST[company] . '<br>
Company Vat Number: '. $_POST[company_vat_number] . '<br>
Reg. Number: '. $_POST[reg_number] . '<br>
E-mail Address: '. $_POST[email_address] . '<br>
Correspondence Address: '. $_POST[correspondence_address] . '<br>
Street Address: '. $_POST[street_address] . '<br>
For Attention Of: '. $_POST[for_attention_of] . '<br>
Telephone Number: '. $_POST[telephone_number] . '<br>
Fax Number: '. $_POST[fax_number] . '<br><br>'
;    
mail ($mailuser, 'Multi-Quant Trial', $mail_body, $header);
echo '<br>Thank You ';


} else {
// *** The input text did not match the stored text, so they failed ***
// *** You would probably not want to include the correct answer, but
//    unless someone is trying on purpose to circumvent you specifically,
//    its not a big deal.  If someone is trying to circumvent you, then
//    you should probably use a more secure way besides storing the
//    info in a cookie that always has the same name! :) ***
echo "<h2><span>Oops!</span></h2>";
echo "Sorry, you did not enter the correct code.<br><br>";
echo "You said " . $_POST["captcha_input"];
echo "<br>while the correct answer was " . $_SESSION["pass"];
echo "<br><br>Please click back and try again";

}
?>

そして、これはフォームです:

<form action="mail/captcha.php" method="post" id="sendemail">
<ol>
<li>
<label for="conditions_of_contract">Conditions of contract</label>
<div class="box">
<input name="conditions_of_contract" type="radio" value="yes" /> Yes
</div>
<div class="box">
<input name="conditions_of_contract" type="radio" value="no" /> No
</div>
</li>
<li>
<label for="main_area">Main area <small>*</small><br />
<span>(* To select multiple main area keep CTRL button down and click on selecttion)</span>
</label>
<select name="main_area" size="1" multiple="multiple">
<option value="Durban">Durban</option>
<option value="South Coast">South Coast</option>
<option value="North Coast">North Coast</option>
<option value="Pietrmaritzburg">Pietrmaritzburg</option>
<option value="Northern Natal">Northern Natal</option>
<option value="Eastern Cape">Eastern Cape</option>
<option value="Free State">Free State</option>
<option value="Mpumalanga">Mpumalanga</option>
<option value="Swaziland">Swaziland</option>
<option value="Cape">Cape</option>
</select>
</li>
<li>
<label>Please enter the code</label>
<img src="mail/captcha_image.php" class="img" />
<input name="captcha_input" type="text" class="num" size="15">
</li>
<li>
<input name="Send" type="submit" class="button" id="Send" value="Submit" />
<input name="reset" type="reset" class="button" id="reset" value="Reset" />
</li>
</ol>
</form>

誰かがこれで私を助けることができます、ありがとう

4

1 に答える 1

0

フォームに対するベンジャミンの解決策は正しいです-それは確かです。

この<select>-Element の値を次の形式で渡すと、

<select name="main_area[]" size="1" multiple="multiple">
    <option value="Durban">Durban</option>
    <option value="South Coast">South Coast</option>
</select>

$_POST 配列の実際の値は次のようになります。

array
   'conditions_of_contract' => string 'yes' (length=3)
   'main' => 
       array
           0 => string 'Durban' (length=11)
           1 => string 'South Coast' (length=15)
   'captcha_input' => string '<Your Captcha Value>' (length=3)
   'Send' => string 'Submit' (length=6)

- 要素の値は、<select>実際には配列として処理されます! だからあなたがするなら

echo $_POST['main_area'];

出力は次のようになります。

Array

値を文字列として取得したい場合は、破裂させることができます:

$mainAreaContents = implode(", ", $_POST['main_area']);
echo $mainAreaContents;

出力は次のようになります。

 Durban, South Coast 

ヒント: $_POST を使用して入力をサニタイズする必要があります。開始点については、PHP -サニタイズ値の配列を参照してください。

于 2012-05-18T17:55:54.340 に答える