HTMLで直接それを行うことはできないと思います(すべてを(を除いて$_POST
)別の配列に押し込みます)。最初に追加の PHP 作業を行う必要があります。
まず、すべての聖なるものを愛するために、HTML 入力名をよりきれいにします。
<form action ="upload.php" method="post">
Name<input id= "n" type="text" name="info_name" /><br />
Address: <input id="a" type = "text" name="info_address" /><br />
City: <input id="c" type = "text" name="info_city" /><br />
</form>
次に、PHP の場合:
//this is how I would do it, simply because I don't like a bunch of if/elseifs everywhere..
//define all the keys (html input names) into a single array:
$infoKeys[0]='name';
$infoKeys[1]='address';
$infoKeys[2]='city';
//define your end array
$information=array();
//now loop through them all and if they're set, assign them to an array. Simple:
foreach ( $infoKeys as $val ){
if(isset($_POST['info_'.$val])){
$information[$val]=$_POST['info_'.$val];
}//end of isset
else{
$information[$val]=null;
}//end of no set (isset===false)
}//end of foreach
//now, when you want to add more input names, just add them to $inputKeys.
//If you used the if/elseif ways, your doc would be plastered in ifs and elseifs.
//So i personally think the looping through the array thing is neater and better.
//but, feel free to change it, as I have a feeling I'll have allot of critics because of this method.
// anyway, that should do it. The var $information should be an array of all your 'info_' html inputs....
ハッピーコーディング!