preluare date din html in php si expuse ca pdf

Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
sterica
Mesaje: 285

preluare date din html in php si expuse ca pdf

Salutare,

Am urmatorul cod din index.php:

Cod: Selectaţi tot

<tr><td>adresa</td></tr>
<tr><td><input id="titlu" class="titlu" style="text" value="TITLU"></td></tr>
si codul care ma ajuta sa export un fisier pdf,
exportPDF.php

Cod: Selectaţi tot

<?php
require ('fpdf181/fpdf.php');

class PDF extends FPDF
  {
    // Page header
    ....
   }
$pdf = new PDF ('P','mm','A4');
$pdf -> AliasNbPages();
$pdf -> AddPage ();
$pdf -> SetFont ('Arial','',10);
$pdf -> Cell (40,10, 'pagina pdf');
$pdf -> Cell (40,10, cum pot aduce valorile din <tr><td></td></tr>  si anume adresa');
$pdf -> Cell(100, 8, aici doresc sa introduc valorile din inputul cu id-ul #titlu, 0);
$pdf -> output ();
Cum pot aduce valori dintr-o celula a unui tabel si dintr-un input intr-un fisier pdf.

Multumesc!

MarPlo Mesaje: 4343
Salut
In mod obisnuit, datele din pagina web sunt trimise la php cu elemnte de formular si buton Submit.
Ceea ce vrei se poate cu Ajax. Se preia datele din codul html cu javascript si cu o functie Ajax se trimit la fisierul php.
Daca nu stii cum se lucreaza cu ajax, poti sa inveti din cursul de pe site: https://marplo.net/ajax/ajax_post_php.html
- Personal, pentru ce am lucrat am facut functia ajaxSend() din acest exemplu:

Cod: Selectaţi tot

<script>
/* Ajax Function
 Send "data" to "php", using the method added to "via", and pass response to "callback" function
 data - json object with data to send, name:value; ex.: {"name1":"val1", "name2":"2"}
 php - address of the php file where data is send
 via - request method, a string: 'post', or 'get'
 callback - function called to proccess the server response
*/
function ajaxSend(url, data, via, callback){
  var obajx =  (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');  // XMLHttpRequest object

  //put data from "data" into a string to be send to "php"
  var str_data ='';
  for(var k in data){
    k = k.toString();  //convert numeric key to string

    //build the string with data to be sent
    str_data += k +'='+ data[k].toString().replace(/\?/g, '%3F').replace(/=/g, '%3D').replace(/&/g, '%26').replace(/[ ]+/g, '%20').replace(/[\+]/g, '%2B') +'&';
  }
  str_data = str_data.replace(/&$/, '');  //delete ending &

  //send data to php
  obajx.open(via, url, true);
  if(via =='post') obajx.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  obajx.send(str_data);

  //check the state request, if completed, pass the response to callback function
  obajx.onreadystatechange = function(){
    if(obajx.readyState == 4){
/// alert(obajx.responseText);  //for debug
      callback(obajx.responseText);
    }
  }
}

//Example Usage
var sendata = {'id1':'val 1', 'id2':'val 2'};  //object with data to send
ajaxSend(sendata, 'test.php', 'post', function(resp){
  alert(resp);
});
</script>

Subiecte similare