Why is my php loop not working? -


ok have php variable $question looks this:

$question['3']['type'] = 'checkbox'; $question['3']['desc'] = 'checkbox question'; $question['3']['deft'] = '1'; $question['3']['opts'] = 'check test 1'; $question['3']['opts'] = 'check test 2'; 

what want have question on survey desc question, , opts multiple answers.

i have statement:

 if ($type == "checkbox") {               if (strtolower($deft) == 'y') { $box_value = "1"; $checked = ' checked'; }                  else { $box_value = "0"; $checked = ''; }               print "<input type=\"checkbox\" name=\"$key\" value=\"$box_value\"$checked>\n<br>";          } 

it works doesn't allow me include question (only answers).

i want this:

 if ($type == "checkbox") {             print "<br>\n";             $i = 1;             foreach ($opts $opt_key => $opt_value) {                 if ($deft == $i) {$checked = "checked=\"checked\""; }                     else { $checked = ''; }                  print "<input type=\"checkbox\" name=\"$key\" value=\"$opt_value\"$checked> - $opt_value <br>\n";                 $i++;             }          } 

i'm getting error because code crappy. can tell me fix code?

thanks

here rest of code

    <?php $thisfile_url = "http://".$_server['server_name'].$_server['php_self']; $thisdir_url  = substr($thisfile_url, 0, strrpos($thisfile_url, '/')).'/'; $thisfile_abs = $_server['script_filename']; $thisdir_abs  =  substr($thisfile_abs, 0, strrpos($thisfile_abs, '/')).'/'; # ------------------------------------------------------------------- # ***** configuration settings *****  # email address want results mailed to. $email_to_send_to = 'nursesurveyresults@aplusprofessionalresumes.com';  # name of survey. want call it? $name_of_survey = 'nurse resume toolkit sales page exit survey';  # template files load. opening template, close template. # template displayed before survey form printed , # template displayed after email sent. or leave empty. $open_template         = $thisdir_abs."templates/sss.open.php"; $close_template        = $thisdir_abs."templates/sss.close.php"; $survey_heading_page   = $thisdir_abs."templates/sss.head.php"; $survey_complete_page  = $thisdir_abs."templates/sss.done.php";  # charset being used messages sent out. iso-8859-1 default, # can use want (unicode, etc). $charset = 'iso-8859-1';  # -------------------------------------------------------------------  # ----------------------- survey form information ------------------- # type: checkbox # deft: y or n default check. # # type: radio # deft: default selected option # opts: array of option values # # type: select # deft: default selected option # opts: array of option values # # type: text # deft: default field text # opts: maxl, size - maxlength , field size # # type: textarea # deft: default textarea field text # opts: rows, cols - row size, column size # # $hidden array of hidden fields. # key being name of field, value value. # # $button_text submit button text # -------------------------------------------------------------------  # ***** sample data *****  $question['1']['type'] = 'select'; $question['1']['desc'] = 'whats current employment status'; $question['1']['deft'] = '1'; $question['1']['opts'][] = 'employed'; $question['1']['opts'][] = 'unemployed'; $question['1']['opts'][] = 'not sure';  $question['2']['type'] = 'radio'; $question['2']['desc'] = 'are looking job'; $question['2']['deft'] = '1'; $question['2']['opts'][] = 'yes'; $question['2']['opts'][] = 'no';  /* $question['1']['type'] = 'text'; $question['1']['desc'] = 'test text'; $question['1']['deft'] = 'blah'; $question['1']['opts']['maxl'] = '30'; $question['1']['opts']['size'] = '10';  $question['2']['type'] = 'checkbox'; $question['2']['desc'] = 'check test 1'; $question['2']['deft'] = 'y'; */  $question['3']['type'] = 'checkbox'; $question['3']['desc'] = 'checkbox question'; $question['3']['deft'] = '1'; $question['3']['opts'] = 'check test 1'; $question['3']['opts'] = 'check test 2';   $question['4']['type'] = 'radio'; $question['4']['desc'] = 'radio test'; $question['4']['deft'] = '2'; $question['4']['opts'][] = 'option 1'; $question['4']['opts'][] = 'option 2'; $question['4']['opts'][] = 'option 3';  $question['5']['type'] = 'select'; $question['5']['desc'] = 'select test'; $question['5']['deft'] = '2'; $question['5']['opts'][] = 'option 1'; $question['5']['opts'][] = 'option 2'; $question['5']['opts'][] = 'option 3';  $question['6']['type'] = 'textarea'; $question['6']['desc'] = 'textarea test'; $question['6']['deft'] = 'default junk'; $question['6']['opts']['rows'] = '10'; $question['6']['opts']['cols'] = '30';  $hidden['test1'] = "test!"; $hidden['test2'] = "testo!"; $button_text     = 'send it!';  # ------------------------------------------------------------------- function my_remove_slashes($st) {   if (get_magic_quotes_gpc()) { return stripslashes($st); }   else { return $st; } }  function security_filter($st) {    $attribs = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|'.               'onmousemove|onmouseout|onkeypress|onkeydown|onkeyup';     $st = my_remove_slashes($st);    $st = stripslashes(preg_replace("/$attribs/i", 'forbidden', $st));    $st = strip_tags($st);    $st = htmlentities($st);    return $st; } # -------------------------------------------------------------------  if (!(empty($open_template))) { include($open_template); }  if (isset($_post['button'])) {    foreach ($_post $key => $value) {      if ($key != 'button') {         if (preg_match('/^hidden_(.*)/i',$key)) {            $value = security_filter($value);            $key = trim(strstr($key,'_'),'_');             if (isset($hidden[$key])) {                 $hidden_data[$key] = $value;             }         }         else {            if (isset($question[$key])) {                $value = security_filter($value);                if ($question[$key]['type'] == 'checkbox') { $value = "yes"; }                $results[$key] = $value;            }         }      }    }     # responses processed, prepare email.     $msg  = "----------------- user info -----------------\n\n";    $msg .= "sent from: ".$_server['remote_host']." [".$_server['remote_addr']."] \n";    $msg .= "coming (referer): ".$_server['http_referer']."\n";    $msg .= "using (user agent): ".$_server['http_user_agent']."\n\n";    $msg .= "---------------------------------------------\n\n";     if (isset($question)) {       $lineflag = false;       foreach ($results $key => $value) {          if ($lineflag == false) {                $msg .= "----------------- questions -----------------\n\n";               $lineflag = true;          }          $msg .= "question: ". $key ." - ". $question[$key]['desc'] ."\n";          $msg .= "response: ". $value . "\n\n";       }       $msg .= "---------------------------------------------\n";    }     $msg .= "\n";     if (isset($hidden_data)) {       $lineflag = false;       foreach ($hidden_data $key => $value) {          if ($lineflag == false) {                $msg .= "---------------- hidden vars ----------------\n\n";               $lineflag = true;          }          $msg .= $key ." - ". $value ."\n";       }       $msg .= "\n---------------------------------------------\n";    }     # prep , send email.    $headers  = "return-path: $email_to_send_to\r\n";    $headers .= "from: $name_of_survey processor < $email_to_send_to >\r\n";    $headers .= "content-type: text/plain; charset=$charset\r\n";    mail($email_to_send_to, $name_of_survey . " mailer", $msg, $headers);     # include template file.    if (!(empty($survey_complete_page))) { include($survey_complete_page); } }  else {       if (!(empty($survey_heading_page))) { include($survey_heading_page); }       print "<form action=\"$thisfile_url\" method=\"post\"> \n";       foreach ($question $key => $value) {          $type = strtolower($question[$key]['type']);          $desc = $question[$key]['desc'];          $deft = $question[$key]['deft'];          $opts = $question[$key]['opts'];           print $desc."\n";           /*          if ($type == "checkbox") {               if (strtolower($deft) == 'y') { $box_value = "1"; $checked = ' checked'; }                  else { $box_value = "0"; $checked = ''; }               print "<input type=\"checkbox\" name=\"$key\" value=\"$box_value\"$checked>\n<br>";          }          */              if ($type == "checkbox") {             print "<br>\n";             $i = 1;             foreach ($opts $opt_key => $opt_value) {                 if ($deft == $i) {$checked = "checked=\"checked\""; }                     else { $checked = ''; }                  print "<input type=\"checkbox\" name=\"$key\" value=\"$opt_value\"$checked> - $opt_value <br>\n";                 $i++;             }          }            if ($type == "radio") {             print "<br>\n";             $i = 1;             foreach ($opts $opt_key => $opt_value) {                 if ($deft == $i) { $checked = " checked=\"checked\""; }                     else { $checked = ''; }                  print "<input type=\"radio\" name=\"$key\" value=\"$opt_value\"$checked> - $opt_value <br>\n";                 $i++;             }          }           if ($type == "select") {              print "<br>\n";              print "<select name=\"$key\">\n";               $i = 1;              foreach ($opts $opt_key => $opt_value) {                  if ($deft == $i) { $checked = ' selected'; }                       else { $checked = ''; }                      print "<option value=\"$opt_value\"$checked>$opt_value</option>\n";                  $i++;              }              print "</select><br>\n";          }           if ($type == "text") {              print "<br>\n";              $size = $opts['size'];              $maxl = $opts['maxl'];              print "<input maxlength=\"$maxl\" size=\"$size\" name=\"$key\" value=\"$deft\"><br>\n";          }           if ($type == "textarea") {              print "<br>\n";              $colz = $opts['cols'];              $rowz = $opts['rows'];              print "<textarea name=\"$key\" rows=\"$rowz\" cols=\"$colz\">$deft</textarea><br>\n";          }         # spacing between survey questions -----------         print "<br>\n";         # --------------------------------------------       }       foreach ($hidden $key => $value) {         print "<input type=\"hidden\" name=\"hidden_$key\" value=\"$value\">\n";      }       print "<input type=\"submit\" name=\"button\" value=\"$button_text\">\n";      print " &nbsp; -- &nbsp; \n";      print "<input type=\"reset\" value=\"clear\">\n";      print "</form>";      print "<center><font size=\"2\">powered <a href=\"http://www.violetonresumes.com\">a plus professional resumes</a></font></center><br>\n"; }  if (!(empty($close_template))) { include($close_template); } ?> 

do need space before $checked in print line?

i'm assuming somewhere breaking out $question $key, $deft , $opts, don't show defined. $key supposed $opt_key?


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -