Note that there are some explanatory texts on larger screens.

plurals
  1. POadding new functionality in existing PHP code
    text
    copied!<p>I have been trying to figure this out. This is a code that is written from someone else long time ago, and now I have been asked to add some new functionality. In short, there is a form that submits to mysql db and generates pdf with filled fields. There is possibility to go back and to edit the form and re-create the pdf. </p> <p>My task was to add two checkboxes in the form. Everything works nice, the checkbox value is sent to the database and the pdf file is created with the checkbox checked or unchecked. </p> <p>However when I go back to edit the form the checkbox is always unchecked, it doesn't fetch the value from the DB. </p> <p>So the existing code to fill in the form is as bellow. I see that there is text, textarea and select...How can I add here the checkbox? Thank you for your help! </p> <pre><code>function fillEoi($eoiFile, $oldPost="NULL") { if (is_array($oldPost) &amp;&amp; count($oldPost)&gt;2) { $handle = fopen($eoiFile, "r"); $contents = fread($handle, filesize ($eoiFile)); fclose ($handle); $tempName = tempnam("/tmp", "FOO"); $handle = fopen($tempName ,"w"); $fileContent=explode("\n",$contents); foreach ($fileContent as $key =&gt; $item) { //Get fieldname; unset($fieldName); $fieldName=strrev(stristr(str_replace("/", "\/", $item),"DB_")); $fieldName=strrev(substr(strrchr($fieldName,"'"),1)); // If is an input field if (stripos($item, "type='text'") &amp;&amp; stripos($item, $fieldName)) { //if (stristr($item, $fieldName)) // $valueAdd=" value='".$oldPost[$fieldName]."'"; $oldPost[$fieldName] = (strpos($item,'DB_INSUREDVALUE')) ? showValue($oldPost[$fieldName]) : $oldPost[$fieldName]; $item=str_replace($fieldName, $fieldName."' value='".$oldPost[$fieldName]."",$item); } elseif (stripos($item, "&lt;/textarea&gt;") &amp;&amp; stripos($item, $fieldName)) { // If is an Textarea $item=str_replace("&lt;/textarea&gt;", $oldPost[$fieldName]."&lt;/textarea&gt;" , $item); } elseif ((stripos($item, $fieldName) &amp;&amp; stripos($item, "&lt;select"))) /* or $selectField==1)*/ { $returnVar['EoiDate'][$fieldName]=$oldPost[$fieldName]; } } $fileContent[$key]=$item; } $newContent=implode("\n",$fileContent); fwrite ($handle, $newContent); fclose($handle); $newEoiFile=$tempName; unset($eoiFile); } else { $newEoiFile=$eoiFile; } $returnVar['EoiPath']=$newEoiFile; return $returnVar; </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload