Jump to content

ADVANCED PHP


napsternapster

Recommended Posts

//the first block of code read the one that reads the content of the dynamically created select ans input text

the second block creates the select and input text dynamically

 

can any one help me to correct the first block code in order to read the value of each selected item from select list and to read the value of the input text

 

 

//this is for the validation and to weather the data inputed from the textbox is being read or not

for($i =1;$i <=4;$i++)

{

  for($s =1;$s<=9;$s++)

  {

  $txt ="txt".$i."_".$s;

foreach ($_POST as $k => $v)

{

echo $_POST[$k]."<br>";

if ($k== 'txtknown_name')

{

    echo "    ".$v;

    }

}

              }

}

====================================================

The folowing code is for input text and select which are creted dynamically

for($i = 1;$i <= 9; $i++)

{

if($i==1)

{

 

$display_info .="<select onchange=\"SelectedElement(this.value,'txt$ct_id"."_$i')\" 

  id=\"select_id$ct_id"."_$i"."\" >

<option value=\"0\">-- Select one --</option>";

}

else if(( $i > 1))

{

$display_info .="<select onchange=\"SelectedElement(this.value,'txt$ct_id"."_$i')\" 

style =\"display:none\"

  id=\"select_id$ct_id"."_$i"."\" >

<option value=\"0\">-- Select one --</option>";

}

//reads the content of the contact entity type and loads it to dropdown list

$select_cet = "select cet_id,cet_desc from contact_entity_type order by cet_desc";

$get_select_cet = $conn->query($select_cet);

 

while($cet_rec = $conn->fetchArray($get_select_cet))

{

$cet_id = $cet_rec['cet_id'];

$cet_desc=$cet_rec['cet_desc'];

 

$display_info  .="<option value=\"$cet_id\">

                $cet_desc</option><br>";

 

}

$display_info .=" </select>";

$next = $i + 1;

 

if(($i > 0 ) && ($i < 9))

{

$display_info .=" <input type=\"text\"  id=\"txt$ct_id"."_$i"."\" style =\"display:none\"

onblur=\"showNext(this.value,'select_id$ct_id"."_$next')\" size=15 maxlength=70>   ";

}

else 

{

$display_info .=" <input type=\"text\"  id=\"txt$ct_id"."_$i"."\" style =\"display:none\"

size=15 maxlength=70>";

}

//echo "select_id".$ct_id."_".$i;

 

if(($i == 3) || ($i ==6))

{

$display_info .= "<br>";

 

}

 

 

 

}

Link to comment
https://forums.phpfreaks.com/topic/140817-advanced-php/
Share on other sites

there is a MUCH easier way to do this. if you use [] in your element names, PHP will create arrays for you automatically. so for example:

<input type="text" name="textfield[]" value="abc" />
<input type="text" name="textfield[]" value="def" />

will translate to an array with "abc" and "def" in it for $_POST['textfield']

 

if you want, you can specify the keys for the array

<input type="text" name="textfield[<?php echo $id;?>]" value="abc" />

or even stack them

<input type="text" name="textfield[<?php echo $catid;?>][<?php echo $id;?>]" value="abc" />

Link to comment
https://forums.phpfreaks.com/topic/140817-advanced-php/#findComment-737034
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.