Is there any way to put php code in contact form 7 to make my trackin?

2

I have some Landing Page in html code, now I am thinking about passing them to wordpress, in contact.php I have a php code that takes some values, I would like to know if I pass it to wordpress those php codes that I have in the contact Can I put them in the plugin contact form 7 of wordpress?

I put the code that I have in contact.php that we use composer

<?php
// Composer's auto-loading functionality
require "vendor/autoload.php";

use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;

//

 $nombreAplicacion = "XXXX";
 $direccionCorreo = "XXXXXXX";
 $idCliente = "XXXXX";

// Nombre del SpreadSheet creada
 $nombreSpreahSheet = "Php Sheet volcado";
 // Nombre de hoja de cálculo
 $hojaCalculo = "Hoja 2";

 $scope = array('https://spreadsheets.google.com/feeds');

 // Inicializamos Google Client
 $client = new Google_Client();
 $client->setApplicationName($nombreAplicacion);
 $client->setClientId($idCliente);

 // credenciales, scope y archivo p12. Agregar el correcto Path al archivo p12
 $cred = new Google_Auth_AssertionCredentials(
 $direccionCorreo,
 $scope,
 file_get_contents('PhpSheet-3a5bbd2c9ada.p12')
);

 $client->setAssertionCredentials($cred);

 // si expiro el access token generamos otro
if($client->isAccessTokenExpired()) {
 $client->getAuth()->refreshTokenWithAssertion($cred);
}

// Obtenemos el access token
$obj_token = json_decode($client->getAccessToken());
$accessToken = $obj_token->access_token;

 // Inicializamos google-spreadsheet-client
 $serviceRequest = new DefaultServiceRequest($accessToken);
 ServiceRequestFactory::setInstance($serviceRequest);

 //Obtenemos los Spreadsheets disponibles para las credenciales actuales
 $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
 $spreadsheetFeed = $spreadsheetService->getSpreadsheets();

// Obtenemos la spreadsheet por su nombre
$spreadsheet = $spreadsheetFeed->getByTitle($nombreSpreahSheet);

// Obtenemos las hojas de cálculo de la spreadsheet obetenida
$worksheetFeed = $spreadsheet->getWorksheets();

// Obtenemos la hoja de cálculo por su nombre
 $worksheet = $worksheetFeed->getByTitle($hojaCalculo);
 $listFeed = $worksheet->getListFeed();

 if(!empty($_SESSION['nombre'])) {
 $dataAgregar = array('gclid' => $_SESSION['gclid'],
 'nombre' => $_SESSION['nombre'],
 'email' => $_SESSION['email'],
 'telefono' =>"'" .$_SESSION['phone'],
 'mensaje' => $_SESSION['mensaje'],
 'landing' =>  $landingP
 );
  $listFeed->insert($dataAgregar);
 }
 if(!empty($_SESSION['nombre2'])) {
  $dataAgregar2 = array('gclid' => $_SESSION['gclid2'],
 'nombre' => $_SESSION['nombre2'],
 'email' => $_SESSION['email2'],
 'telefono' =>"'" .$_SESSION['phone2'],
 'mensaje' => $_SESSION['mensaje2'],
 'landing' =>  $landingP2
 );
 $listFeed->insert($dataAgregar2);
 }   
 ?>

As we have to use composer in the theme folder I have to upload an index.php, a vendor folder and some composer files, as in the theme we already have an index.php I do not know if it also serves to catch the code the index .php and enter it in the theme index.php to make composer work?

    
asked by AitorUdabe 29.09.2016 в 17:12
source

1 answer

1

You could add the following code in the functions.php:

add_action('wpcf7_before_send_mail', 'mi_funcion');

function mi_funcion($cf7) {
    //Código PHP
}

The way to deal with the sending variables is accessing the variable $_POST['nombre_de_mi_campo'] where 'nombre_de_mi_campo' corresponds to the name defined in the contact form form 7. You just need to add your slightly modified code to access the variables correctly within the function.

I edit the answer because you have edited the question

Well, suddenly we are talking about composer, I can not say enough about it, one way to use it is to create a directory in the path "themes/mi_tema/directorio" where to host everything necessary, so when you run "composer install" you will create the directory vendor and will install in it the dependencies that you specify in the json (I think that's the case).

Once you have done this, add the following line in functions.php or in wp-config.php :

require_once(__DIR__ . '/vendor/autoload.php'); 

and it should work.

You comment that you get an error 500, this in wordpress can occur due to lack of memory in PHP or by an error in htaccess .

    
answered by 29.09.2016 в 18:48