I have a following html markup (it's a basic structure to let you know, as some people will ask me where is the <form>
tag. Consider it being there.)
<input type="text" name="set_val_1" id="set_val_1" value="1"/>
<input type="text" name="set_val_2" id="set_val_2" value="2"/>
<input type="text" name="max_risk_id" id="max_risk_id" value="5"/>
<input type="submit" value="Enter" name="submit_button"/>
Now when the form will be submitted I want to have a code to detect whether any POST appeared in the format "set_val_
".
An algorithm based on my issue:
if(isset($_POST['something with the pattern (set_val_)']))
{
$flag = 1;
$val_string = "";
}
if($flag == 1)
{
$max_id = $_POST['max_risk_id'];
for($i = 1; $i<=$max_id; $i++)
{
if(isset($_POST['set_val_'.$i]))
{
$val_string = $val_string. $_POST['set_val_'.$i].",";
}
}
}
How can I check whether a post occurred of a particular name format?
New edit explaining why I need this
I have multiple multiselect, check the fiddle:
http://jsfiddle.net/p0b4j5o8/24/
So for that, I am having the fetching data of the multi-selects in this fashion
if(isset($_POST['max_risk_id']))
{
$max_id = $_POST['max_risk_id'];
for($i = 1; $i<=$max_id; $i++)
{
$offer_combo = '';
if(isset($_POST['risk_mitigator_offer_'.$i]) && isset($_POST['risk_weight_'.$i]))
{
$offer_risk = $_POST['risk_mitigator_offer_'.$i];
$risk_weight = $_POST['risk_weight_'.$i];
print_r($offer_risk);
foreach($offer_risk as $fr)
{
$offer_combo = $offer_combo . $fr . ",";
}
$offer_combo = trim($offer_combo,",");
$mitigator_insert_query = "INSERT INTO mt_risk_mitigator
(camp_id , risk_combination, risk_weight)
VALUES ('".$mysql['camp_id']."','$offer_combo','$risk_weight')";
mysql_query($mitigator_insert_query);
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…