0
The script below works perfectly when my site is without SSL, ie with the domain http://www.dominio.com.br, but when I activate SSL for the site to look like https://www.dominio.com.br, Google Chrome displays error "ERR_CONNECTION_CLOSED" when I try to pass more than 5780 characters via URL.
Here’s what I’m thinking of doing: Take all values store in a single variable array, and then extract them on the next page. But I don’t know how to do this, can someone please help?
<?php
function redirecionaVariaveisCF7() {
?>
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '4' == event.detail.contactFormId ) {
var inputs = event.detail.inputs;
for ( var i = 0; i < inputs.length; i++ ) {
if ( 'nome' == inputs[i].name ) {
var nome = inputs[i].value;
}
if ( 'email' == inputs[i].name ) {
var email = inputs[i].value;
}
}
window.location.href = 'testes/wp_01/teste-sucesso/?nome='+nome+'&email='+email;
}
}, false );
</script>
<?php
}
add_action( 'wp_footer', 'redirecionaVariaveisCF7' );
add_action( 'the_content', 'exibeVariaveisCF7' );
function exibeVariaveisCF7($cf7_exibe_mensagem_conteudo) {
if(is_page('teste-sucesso')){
$nome = htmlspecialchars($_GET["nome"]);
$email = htmlspecialchars($_GET["email"]);
?><script>
function cont(){
var conteudo = document.getElementById('boxImpressaoDisponivel').innerHTML;
tela_impressao = window.open('https://www.meudominio.com.br');
tela_impressao.document.write(conteudo);
tela_impressao.window.print();
tela_impressao.window.close();
}
</script><?php
$cf7_exibe_mensagem_txt = "<div class='container' id='boxImpressaoDisponivel'> <br> <center><img src='https://www.meudominio.com.br/testes/wp_01/wp-content/uploads/2019/03/logo.png' width='120'></center> <br><br><br>";
if ($nome != NULL){
$cf7_exibe_mensagem_txt .= "<b>Nome:</b> " . $nome ."<br>";
}
if ($email != NULL){
$cf7_exibe_mensagem_txt .= "<b>E-mail:</b> " . $email ."<br>";
}
$cf7_exibe_mensagem_txt .= "</div>";
$cf7_exibe_mensagem_txt .= "<div class='container'>";
$cf7_exibe_mensagem_txt .= "<input type='button' onclick='cont();' value='Imprimir'>";
$cf7_exibe_mensagem_txt .= "</div>";
}
$cf7_exibe_mensagem_resultado = $cf7_exibe_mensagem_txt . $cf7_exibe_mensagem_conteudo;
return $cf7_exibe_mensagem_resultado;
}
If you are going to pass many variables I recommend that you use POST instead of going through URI, if you want to keep values of your javascript variables between payload you can use localStorage.
– brunox99x
I also thought of using POST the problem that by default this code sends as GET do not know where I change his method to send as POST
– Fernando Amorim
I think this localStorage may help, but I’m not being able to adapt the code to add this, you can tell me which parts of the code I should switch to localStorage.setItem and localStorage.getItem please
– Fernando Amorim
To change the method of sending variables go in your submit form in the form action put POST method, but it seems that you are doing this manually here window.location.href going through /?var=value. Actually your code is quite messy mixing html, js and php, I suggest you redo it so you don’t end up giving problems like time. I suggest you create one form page and create another to process your request. If you want a good print to appear when clicking the submit button I suggest using Ajax | View<=>Controll.
– brunox99x