3 Replies - 346 Views - Last Post: 21 May 2013 - 03:46 AM Rate Topic: -----

#1 zenko44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-February 12

problems with functions not executing properly.

Posted 21 May 2013 - 03:13 AM

Hi Guys,
i have built an online form, with 2 functions which consist of 1 DOMPDF function taking the form and turning it into a pdf file and the other a simple email which takes the last part of the webpage which is an attachment link, so they can use a predetermined email and email address with out having to leave the webpage.
the code is
<?php
  
  function first(){
     if($_POST &&!empty($_POST['ebs'])) {
    $content = '';
    foreach ($_POST as $key => $value) {
        if ($key == 'name') {
            $name = $value;
        } else {
            $content .= $value;
        }
    }

     $table = $_POST['table'];    
    $table2 = $_POST['table2'];
    $q1 = $_POST['q1'];
    $ans1 = $_POST['ans1'];

    $ans12 = $_POST['ans12'];


    $ans13 = $_POST['ans13'];


    $ans14 = $_POST['ans14'];

    $ans15 = $_POST['ans15'];

    $ans16 = $_POST['ans16'];

    $ans17 = $_POST['ans17'];

    $ans18 = $_POST['ans18'];

    $ans19 = $_POST['ans19'];

    $ans20 = $_POST['ans20'];

    $ans21 = $_POST['ans21'];

    $ans22 = $_POST['ans22'];

   
    $sec1 = "<html><table name=\"table\"><tr><td><p name=\"ebs1\">Ebs number</p></td><td>";
    $ebs = $_POST['ebs'];
    $sec2 = "</td></tr><tr><td><p name=\"name2\">Name</p></td><td>";
    $name1 = $_POST['name1'];
    $sec3 = "</td></tr></table>";
    $sec4 = "<p name=\"q1\"> Ray wants to make light orange paint. He needs to mix red and yellow in a ratio of 1:2 he <br/>
            uses a table to work out how much paint he will have</p>";
    $sec5 = "<table name=\"table3\" border=\"1\" width=\"90%\">
              <tr>
                <td><p name=\"table1a1\">Red</p></td>
                <td><p name=\"table1a2\">Yellow</p></td>
                <td><p name=\"table1a3\">light orange</p></td>
              </tr>
              <tr>
                <td><h3 name=\"table1a4\">1</h3></td>
                <td><h3 name=\"table1a5\">2</h3></td>
                <td><h3 name=\"table1a6\">3</h3></td>
              </tr>
              <tr>
                <td><h3 name=\"table1a7\">2</h3></td>
                <td><h3 name=\"table1a8\">4</h3></td>
      <td>";
    $ans1 = $_POST['ans1'];
    $sec6 = "</td>
              </tr>
              <tr>
                <td><h3 name=\"table1a9\">3</h3></td>
                <td>";
    $ans2 = $_POST['ans2'];
    $sec7 = "</td>
                <td>";
    $ans3 = $_POST['ans3'];
    $sec8 = "</td>
              </tr>
              <tr>
                <td>";
    $ans4 = $_POST['ans4'];
    $sec9 = "</td>
                <td><h3 name=\"table1a10\">10</h3></td>
                <td>";
    $ans5 = $_POST['ans5'];
    $sec10 = "</td>
              </tr>
              <tr>
                <td><h3 name=\"table1a11\">10</h3></td>
                <td>";
    $ans6 = $_POST['ans6'];
    $sec11 = "</td>
                <td>";
    $ans7 = $_POST['ans7'];
    $sec12 = "</td>
              </tr>
              <tr>
                <td><h3 name=\"table1a12\">25</h3></td>
                <td>";
    $ans8 = $_POST['ans8'];
    $sec13 = "</td>
                <td>";
    $ans9 = $_POST['ans9'];
    $sec14 = "</td>
              </tr>
              <tr>
                <td>";
    $ans10 = $_POST['ans10'];
    $sec15 = "</td>
                <td><h3 name=\"table1a13\">100</h3></td>
                <td>";
    $ans11 = $_POST['ans11'];
    $sec16 = "</td>
      </tr>
      </table>
      <ul>
                    <li><p name=\"q2\"> 1)      Complete this table</p></li>
                    <li><p name=\"q3\"> 2)      Ray needs 21 litres of light orange. How many litres of red and how many litres <br/>of yellow paint does he need?</p><br/>";
    
    $sec17 = "<li><p name=\"q4\"> 3)      Tamzin is making green paint. She mixes 5 litres of blue with yellow.</p><br/>";
    $sec18 = "<li><p name=\"q3\"> (a) 18 litres of blue with 9 litres of yellow.</p><br/>";
    $sec19 = "<li><p name=\"q6\"> (B)/>/> How much yellow does she mix with 25 litres of blue?</p><br/>";
    $sec20 = "<li><p name=\"q7\"> (c) How much green paint has she just made?</p><br/>";
    $sec21 = "<li><p name=\"q8\"> (d) How much Blue does she mix with 6 litres of yellow?</p><br/>";
    $sec22 = "</ul><li> <p name=\"q9\">4)      this table shows how to make different greens.</p><li><ul><li><table name=\"table2\" border=\"1\"><tr><td><p name=\"q10\">Colour</p></td><td><p name=\"q11\">Blue : Yellow</p></td></tr><tr><td><p name=\"q12\">Very dark green</p></td><td><p name=\"q13\">3:1</p></td></tr><tr><td><p name=\"q14\">Dark green</p></td><td><p name=\"q15\">2:1</p></td></tr><tr><td><p name=\"q16\">Mid green</p></td><td><p name=\"q17\">1:1</p></td></tr><tr><td><p name=\"q18\">Light green</p></td><td><p name=\"q19\">1:2</p></td></tr><tr><td><p name=\"q20\">Very light green</p></td><td><p name=\"q21\">1:3</p></td></tr></table></li></ul>";
    $sec23 = "<li> <p name=\"q22\">Which green do you get if you mix the following?</p><br/>";
    $sec24 = "<li><p name=\"q23\"> (a) 18 litres of blue with 9 litres of yellow.</p><br/>";
    $sec25 = "<li><p name=\"q24\"> (B)/>/> 10 litres of blue with 10 litres of yellow.</p><br/>";
    $sec26 = "<li><p name=\"q25\"> (c) 9 litres of blue with 3 litres of yellow.</p><br/>";
    $sec27 = "<li><p name=\"q26\"> (d) 4 litres of blue and 12 litres of yellow.</p><br/>";
    $br = "<br/>";
    $style = "<head>
    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">
  </head>";
    
    
    
    
    include_once('dompdf/dompdf_config.inc.php' );
     
    $dompdf = new DOMPDF();    
    $dompdf->load_html($sec1.$ebs.$sec2.$name1.$sec3.$sec4.$sec5.$ans1.$sec6.
                      $ans2.$sec7.$ans3.$sec8.$ans4.$sec9.$ans5.$sec10.$ans6.
                       $sec11.$ans7.$sec12.$ans8.$sec13.$ans9.$sec14.$ans10.$sec15.
                      $ans11.$sec16.$ans12.$sec17.$ans13.$sec18.$ans14.$sec19.$ans15.
                      $sec20.$ans16.$sec21.$ans17.$sec22.$sec23.$ans18.$sec24.$ans19.
                      $sec25.$ans20.$sec26.$ans21.$sec27.$ans22);

    $dompdf->render();
    $dompdf->stream('Sample2.pdf');   

  
  }
    
    
    
  }
  
  function second(){
   
    $strTo = "test@test.com";
    $strSubject = "test emails";
    $strMessage = "This is a test email";
      //*** Uniqid Session ***//
    
  $strSid = md5(uniqid(time()));
    $strHeader = "";
    $strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";
    $strHeader .= "MIME-Version: 1.0\n";
    $strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
    $strHeader .= "This is a multi-part message in MIME format.\n";
    $strHeader .= "--".$strSid."\n";
    $strHeader .= "Content-type: text/html; charset=utf-8\n";
    $strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
    $strHeader .= $strMessage."\n\n";
    
  //*** Attachment ***//
    if($_FILES["fileAttach"]["name"] != "")
    {
      $strFilesName = $_FILES["fileAttach"]["name"];
      $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"]))); 
      $strHeader .= "--".$strSid."\n";
      $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; 
      $strHeader .= "Content-Transfer-Encoding: base64\n";
      $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
      $strHeader .= $strContent."\n\n";
    }  

  $flgSend = @mail($strTo,$strSubject,null,$strHeader);  // @ = No Show Error //
    if($flgSend)
    {
      echo "Mail send completed.";
      
    }
    else
    {
      echo "Cannot send mail.";
    }
  }
  
  
  
  ?>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
        <?php
        if (isset($error)) {echo $error;}?>
    <div id="content">

        <form method="post" action="ftest.php">

          <table name="table"><tr><td><p name="ebs1">Ebs number</p></td><td><input name="ebs" type="textarea"/></td></tr>
            <tr><td><p name="name2">Name</p></td><td><input name="name1" type="textarea"/></td></tr></table>
          <p name="q1"> Ray wants to make light orange paint. He needs to mix red and yellow in a ratio of 1:2 he <br/>
            uses a table to work out how much paint he will have</p>
          
          <!--<a href="javascript:hideshow(document.getElementById('adiv'))">Show Table</a>-->
          
         <ul>
           
           <li><ul>
             <li><p name="q2"> 1)      Complete this table</p></li>
             <li> <article id="post-53" class="post-53 post type-post status-publish format-standard hentry category-uncategorized no-thumbnail">
  <a href="javascript:hideshow(document.getElementById('adiv'))"><span class="no-thumbnail">Show Table</span></a>
           </article></li></ul></li></ul>
          
          
         <script type="text/javascript">
function hideshow(which){
if (!document.getElementById)
return
if (which.style.display=="none")
which.style.display="block"
else
which.style.display="none"
}
</script> 

                 <div id="adiv" style="font:24px bold; display: none"> 
                   <br/> 
          <table name="table3" align="center" id="tab2" border="1" >
              <tr>
                <td><p name="table1a1">Red</p></td>
                <td><p name="table1a2">Yellow</p></td>
                <td><p name="table1a3">light orange</p></td>
              </tr>
              <tr>
                <td><h3 name="table1a4">1</h3></td>
                <td><h3 name="table1a5">2</h3></td>
                <td><h3 name="table1a6">3</h3></td>
              </tr>
              <tr>
                <td><h3 name="table1a7">2</h3></td>
                <td><h3 name="table1a8">4</h3>
             
                  </div></td>
                <td>
                 <input type="textarea" name="ans1"/>                
                </td>
            </tr>
              <tr>
                <td><h3 name="table1a9">3</h3></td>
                <td><input type="textarea" name="ans2"/></td>
                <td><input type="textarea" name="ans3"/></td>
              </tr>
              <tr>
                <td><input type="textarea" name="ans4"/></td>
                <td><h3 name="table1a10">10</h3></td>
                <td><input type="textarea" name="ans5"/></td>
              </tr>
              <tr>
                <td><h3 name="table1a11">10</h3></td>
                <td><input type="textarea" name="ans6"/></td>
                <td><input type="textarea" name="ans7"/></td>
              </tr>
              <tr>
                <td><h3 name="table1a12">25</h3></td>
                <td><input type="textarea" name="ans8"/></td>
                <td><input type="textarea" name="ans9"/></td>
              </tr>
              <tr>
                <td><input type="textarea" name="ans10"/></td>
                <td><h3 name="table1a13">100</h3></td>
                <td><input type="textarea" name="ans11"/></td>
              </tr>
                  </table></div>
                  <ul style="list-style-type:none;">
                    
                    <li><p name="q3"> 2)     Ray needs 21 litres of light orange. How many litres of red and how many litres <br/>of yellow paint does he need?</p><br/></li><li>
                       <div id="theText">
                         <a href="javascript:txtrep(document.getElementById('ans12'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br>
                  <!--<input type = "button" value = "Click to replace text" onclick = "txtrep()">-->
                  <script type = "text/javascript">
                    function txtrep() {
                      var newtext = "<input type=\"text\" id=\"ans12\" name=\"ans12\"/>";
                      document.getElementById('theText').innerHTML = newtext;
                    }
                  </script>
                      </li>
                    <li><p name="q4"> 3)     Tamzin is making green paint. She mixes 5 litres of blue with yellow.</p><br/></li>
                    <li>
                      <div id="theText1">
                         <a href="javascript:txtrep1(document.getElementById('ans13'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br>
                     <script type = "text/javascript">
                    function txtrep1() {
                      var newtext = "<input type=\"text\" id=\"ans13\" name=\"ans13\"/>";
                      document.getElementById('theText1').innerHTML = newtext;
                    }
                  </script>
                    </li>
                    
                      <li><p name="q5"> (a) What is the ratio of blue paint to yellow paint?</p><br/></li>
                      <li><div id="theText2">
                         <a href="javascript:txtrep2(document.getElementById('ans14'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br>
                     <script type = "text/javascript">
                    function txtrep2() {
                      var newtext = "<input type=\"text\" id=\"ans14\" name=\"ans14\"/>";
                      document.getElementById('theText2').innerHTML = newtext;
                    }
                  </script>
                    </li>
                      <li><p name="q6"> (B)/>/> How much yellow does she mix with 25 litres of blue?</p></li>
                      <li><br/><div id="theText5">
                         <a href="javascript:txtrep3(document.getElementById('ans15'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br>
                     <script type = "text/javascript">
                    function txtrep3() {
                      var newtext = "<input type=\"text\" id=\"ans15\" name=\"ans15\"/>";
                      document.getElementById('theText5').innerHTML = newtext;
                    }
                  </script>
                    </li>
                      <li><p name="q7"> (c) How much green paint has she just made?</p><br/></li>
                      <li><div id="theText6">
                         <a href="javascript:txtrep6(document.getElementById('ans16'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br>
                     <script type = "text/javascript">
                    function txtrep6() {
                      var newtext = "<input type=\"text\" id=\"ans16\" name=\"ans16\"/>";
                      document.getElementById('theText6').innerHTML = newtext;
                    }
                  </script>
                    </li>
                      <li><p name="q8"> (d) How much Blue does she mix with 6 litres of yellow?</p><br/></li>
                      <li><div id="theText7">
                         <a href="javascript:txtrep7(document.getElementById('ans17'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br>
                     <script type = "text/javascript">
                    function txtrep7() {
                      var newtext = "<input type=\"text\" id=\"ans17\" name=\"ans17\"/>";
                      document.getElementById('theText7').innerHTML = newtext;
                    }
                  </script>
                    </li>
                    
                        <li> <p name="q9">4)      This table shows how to make different greens.</p><li>
                      <ul style="list-style-type:none;">
                        <li>
                          <article id="post-53" class="post-53 post type-post status-publish format-standard hentry category-uncategorized no-thumbnail">
                            <a href="javascript:hideshow(document.getElementById('adiv1'))"><span class="no-thumbnail">Show Table</span></a>
                            </article>

                 <div id="adiv1" style="font:24px bold; display: none"> 
                   <br/> 
                          <table align="center" name="table2" border="1">
                            <tr>
                              <td><p name="q10">Colour</p></td>
                              <td><p name="q11">Blue : Yellow</p></td>
                            </tr>
                             <tr>
                              <td><p name="q12">Very dark green</p></td>
                               <td><p name="q13">3:1</p></td>
                            </tr>
                             <tr>
                              <td><p name="q14">Dark green</p></td>
                               <td><p name="q15">2:1</p></td>
                            </tr>
                             <tr>
                              <td><p name="q16">Mid green</p></td>
                               <td><p name="q17">1:1</p></td>
                            </tr>
                             <tr>
                              <td><p name="q18">Light green</p></td>
                               <td><p name="q19">1:2</p></td>
                            </tr>
                             <tr>
                              <td><p name="q20">Very light green</p></td>
                               <td><p name="q21">1:3</p></td>
                            </tr>
                          </table>
                        </div>
                        </li>
                      </ul>
                      <li> <p name="q22">Which green do you get if you mix the following?</p><br/></li>
                            <li><div id="theText18">
                         <a href="javascript:txtrep18(document.getElementById('ans18'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br></li>
                            <script type = "text/javascript">
                    function txtrep18() {
                      var newtext = "<input type=\"text\" id=\"ans18\" name=\"ans18\"/>";
                      document.getElementById('theText18').innerHTML = newtext;
                    }
                  </script>
                          
                      <li><p name="q23"> (a) 18 litres of blue with 9 litres of yellow.</p><br/></li>
                            <li><div id="theText19">
                         <a href="javascript:txtrep19(document.getElementById('ans19'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br></li>
                            <script type = "text/javascript">
                    function txtrep19() {
                      var newtext = "<input type=\"text\" id=\"ans19\" name=\"ans19\"/>";
                      document.getElementById('theText19').innerHTML = newtext;
                    }
                  </script>
                          
                      <li><p name="q24"> (B)/>/> 10 litres of blue with 10 litres of yellow.</p><br/></li>
                            <li><div id="theText20">
                         <a href="javascript:txtrep20(document.getElementById('ans20'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br></li>
                            <script type = "text/javascript">
                    function txtrep20() {
                      var newtext = "<input type=\"text\" id=\"ans20\" name=\"ans20\"/>";
                      document.getElementById('theText20').innerHTML = newtext;
                    }
                  </script>
                          
                      <li><p name="q25"> (c) 9 litres of blue with 3 litres of yellow.</p><br/></li>
                            <li><div id="theText21">
                         <a href="javascript:txtrep21(document.getElementById('ans21'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br></li>
                            <script type = "text/javascript">
                    function txtrep21() {
                      var newtext = "<input type=\"text\" id=\"ans21\" name=\"ans21\"/>";
                      document.getElementById('theText21').innerHTML = newtext;
                    }
                  </script>
                          
                        <li><p name="q26"> (d) 4 litres of blue and 12 litres of yellow.</p><br/></li>
                            <li><div id="theText22">
                         <a href="javascript:txtrep22(document.getElementById('ans22'))"><span class="no-thumbnail"> Click here to answer</span></a>
                    </div><br></li>
                            <script type = "text/javascript">
                    function txtrep22() {
                      var newtext = "<input type=\"text\" id=\"ans22\" name=\"ans22\"/>";
                      document.getElementById('theText22').innerHTML = newtext;
                    }
                  </script>
                          
                      </li>
                          <tr>
    <td>Attachment</td>
    <td><input name="fileAttach" type="file"></td>
  </tr>
                    </li>
                  </ul>
          <a href="?run=first">func 1   </a>
        </form>
      
     
<?php 

if (isset($_GET['run'])) $linkchoice=$_GET['run']; 
else $linkchoice=''; 

switch($linkchoice){ 

case 'first' : 
    first(); 
    break; 

case 'second' : 
    second(); 
    break; 




} 

?> 
    <a href="?run=second" >Link to Second</a>
<br> 
<a href="?run=0">Refresh No run</a> 
</div>
</body></html>


would anyone know how to get these functions working properly.

many thanks
steve

Is This A Good Question/Topic? 0
  • +

Replies To: problems with functions not executing properly.

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: problems with functions not executing properly.

Posted 21 May 2013 - 03:19 AM

Quote

would anyone know how to get these functions working properly.


You can't dump that much code and say "get it working properly" without giving us an idea HOW it's NOT working properly.

Quote

$flgSend = @mail($strTo,$strSubject,null,$strHeader);  // @ = No Show Error //


Perhaps UNTIL you get it working properly you shouldn't suppress errors like that. And sending mail with attachments is a little difficult to do using the built-in mail function; you're better off using something like PHPmailer or SwiftMailer.
Was This Post Helpful? 0
  • +
  • -

#3 zenko44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-February 12

Re: problems with functions not executing properly.

Posted 21 May 2013 - 03:35 AM

ah right sorry i will amend it now thanks for the heads up :)/>

This post has been edited by Dormilich: 21 May 2013 - 03:39 AM

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3523
  • View blog
  • Posts: 12,031
  • Joined: 12-December 12

Re: problems with functions not executing properly.

Posted 21 May 2013 - 03:46 AM

Tables and paragraphs don't have name attributes, and the align attribute (for tables and other elements) and "javascript:" are obsolete.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1