Foros del Web » Programando para Internet » Jquery »

pasar datos a jquery con variable de php

Estas en el tema de pasar datos a jquery con variable de php en el foro de Jquery en Foros del Web. hola tengo esta pagina Código PHP: <html> <head>   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />   <title>Newsletter Signup Form</title> <?php //if all they have hit submit, filled in required fields, the emails match & the the sum is answered correctly //if($_POST['submit'] && $_POST['email'] != '' && $_POST['emailConfirm'] != '' && $_POST['firstName'] != '' && $_POST['lastName'] != '' && $_POST['email'] == $_POST['emailConfirm'] && $_POST['spamCheck'] == $_POST['number1'] + $_POST['number2']){   // codificacio de variables //$email = iconv("UTF-8", "ISO-8859-1", $_POST['email']); $email  =  $_POST [ 'email' ];  $firstName  =  iconv ( ...
  #1 (permalink)  
Antiguo 26/11/2010, 03:57
Avatar de engonga
Usuario no validado
 
Fecha de Ingreso: marzo-2002
Ubicación: Buenos Aires
Mensajes: 1.300
Antigüedad: 22 años, 1 mes
Puntos: 8
pasar datos a jquery con variable de php

hola tengo esta pagina

Código PHP:
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  <title>Newsletter Signup Form</title>

<?php

//if all they have hit submit, filled in required fields, the emails match & the the sum is answered correctly
//if($_POST['submit'] && $_POST['email'] != '' && $_POST['emailConfirm'] != '' && $_POST['firstName'] != '' && $_POST['lastName'] != '' && $_POST['email'] == $_POST['emailConfirm'] && $_POST['spamCheck'] == $_POST['number1'] + $_POST['number2']){  
// codificacio de variables

//$email = iconv("UTF-8", "ISO-8859-1", $_POST['email']);
$email $_POST['email']; 
$firstName iconv("UTF-8""ISO-8859-1"$_POST['firstName']);
//$firstName = $_POST['firstName'];
$lastName iconv("UTF-8""ISO-8859-1"$_POST['lastName']);
//$lastName = $_POST['lastName'];
$city iconv("UTF-8""ISO-8859-1"$_POST['city']);
//$city = $_POST['city'];

// final codificacio variables

//if($_POST['submit'] && $_POST['email'] != '' && $_POST['firstName'] != '' && $_POST['lastName'] != '' && $_POST['city'] != '' && $_POST['spamCheck'] == $_POST['number1'] + $_POST['number2']){  
if($_POST['submit'] && $email != '' && $firstName != '' && $lastName != '' && $city != '' && $_POST['spamCheck'] == $_POST['number1'] + $_POST['number2']){  
  
  
//the url we are going to post to. update this to point to your phplist installation
  //$url = "http://mysite.com/lists/?p=subscribe"; 
  
$url "http://www.elcomercio.biz/mailing/?p=subscribe&id=1";
  
  
//EDIT THESE!!!
  //the information we are going to send
  
$postfields = array( 
    
'email' => $email,
    
//'emailconfirm' => $_POST['emailConfirm'],
    
'list[2]' => 'signup'// s'ha de posar entre [] el numero de la llista
    
'listname[2]' => 'elcomercio'//el nom de la llista
    
'subscribe' => 'subscribe'
    
'attribute1' => $firstName//additional attributes (varies depending on phplist setup)
    
'attribute2' => $lastName,  //if you view the source on your phplist subscribe page
    
'attribute3' => $city,      //you should be able to see figure out the attribute numbers
    //'attribute4' => $_POST['state'],     //for each of your additional fields
    //'attribute5' => $_POST['zip'], 
    //'attribute6' => $_POST['country'], 
    
'htmlemail' => '1' 
  
);
    
  
//initiate a new session and return a cURL handle
  
$ch curl_init();
  
// follow all headers in the HTTP response from the server
  
curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
  
curl_setopt($chCURLOPT_URL$url );
  
// enable http posts ....
  
curl_setopt ($chCURLOPT_POST1);
  
// set form posting ....
  
curl_setopt ($chCURLOPT_POSTFIELDS,$postfields);
  
//output returned to a variable
  
curl_setopt($chCURLOPT_RETURNTRANSFERtrue );
  
// include server header responses ..
  
curl_setopt($chCURLOPT_HEADERfalse);
  
$returned_post curl_exec ($ch);
  
//close session 
  
curl_close ($ch);
 
  
//la búsqueda de la respuesta para ver si funcionaba
  
if(stristr($returned_post'Gracias por suscribirse a nuestras listas')){
    
//if ($oklinea == "ok"){
    //
    
$host  $_SERVER['HTTP_HOST'];
    
$uri   rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    
$extra 'phplist.php?signup=success';
    
header("Location: http://$host$uri/$extra");
    
//header('Location: /phplist.php?signup=success');
    //
    //$message[] = array(
      //'text' => "Ok ahora sera redirigido",
      //'class' => 'success'
    //);
  
}
  elseif(
stristr($returned_post'Por favor, introduzca su')){
    
$message[] = array(
      
'text' => "<b>Email no v&aacute;lido</b> Porfavor introduce email v&aacute;lido y prueba de nuevo.",
      
'class' => 'error'
    
);
  }
  else {
    
$message[] = array(
      
'text' => "<b>Oops!! algo sali&oacute; mal!</b> Si el problema persiste pongase en contacto con <a href='mailto:[email protected]'> El Administrador </a>",
      
'class' => 'error'
    
);
  }
}

//if they didn't answer the sum right
if($_POST['spamCheck'] != $_POST['number1'] + $_POST['number2']){
  
$message[] = array(
    
'text' => "No has respondido a la suma correcta! Prueba de nuevo.",
    
'class' => 'error'
  
);
}

//if the emails dont match
//if($_POST['submit'] && $_POST['email'] != $_POST['emailConfirm']){
  //$message[] = array(
    //'text' => "La dirección de correo electrónico 'que nos ha facilitado no coinciden. Por favor, revise su ortografía e inténtelo de nuevo.",
    //'class' => 'error'
  //);
//}

//if the hit submit and didn't submit all the required values
if($_POST['submit']){
  if(
$_POST['email'] == '' || $_POST['$city'] == '' || $_POST['firstName'] == '' || $_POST['lastName'] == ''){
      
//if($email == '' || $city == '' || $firstName == '' || $lastName == ''){
    
$message[] = array(
      
'text' => "Por favor, introduzca un valor para todos los campos obligatorios.",
      
'class' => 'error'
    
);
  }
}

//success message
if($_GET['signup'] == 'success'){
  
$message[] = array(
    
'text' => "<b>Tu correo electr&oacute;nico ha sido a&ntilde;adido a nuestro sistema</b>. Le enviaremos por correo electr&oacute;nico una solicitud para confirmar tu suscripci&oacute;n. Por favor, aseg&uacute;rate de hacer clic en el v&iacute;nculo en ese mensaje para confirmar su suscripci&oacute;n. Por favor, a&ntilde;ade [email protected] a tu libreta de direcciones.",
    
'class' => 'success',
    
'classok' => 'successok'
  
);
  
}

?>

  
  <!-- GET JQUERY FROM GOOGLE -->
  <!-- REMOVE THESE TO DISABLE AJAX POST -->
  <script type="text/javascript" src="src/jquery/jquery.js"></script>
  <script type="text/javascript" src="src/ajax_phplist.js"></script>
<link href="css/style_phplist.css" rel="stylesheet" type="text/css">
</head>
<body>

  <!-- MESSAGES TO BE DISPLAYED -->
  <div id='messageBox'>
  <?php
    
foreach($message as $msg){
      print(
"<p class='message ".$msg['class']."'>".$msg['text']."</p>");
    }
  
?>
</div>
 
  <!-- SUBMISSION FORM -->
  <form action="phplist.php" method="post" id="phplistSubscribe">
    <h3>Required Information</h3>
    <p class="description">Information we need to be able to send you an email.</p>
    <label>Email <span class="required">*</span></label> <input id="email" type="text" name="email" value="<?php print($email); ?>" /><br />
    
    <label>Nombre <span class="required">*</span></label> <input id="firstName" type="text" name="firstName" value="<?php print($firstName); ?>" /><br />
    <label>Apellidos <span class="required">*</span></label> <input id="lastName" type="text" name="lastName" value="<?php print($lastName); ?>" /><br />
    <label>Poblaci&oacute;n <span class="required">*</span></label> <input id="city" type="text" name="city" value="<?php print($city); ?>" /><br />
    <br />
<br />
  
   
  
    <h3>Anti-Spam</h3>
    <p class="description">An easy sum to test if you are a human or spambot.</p>
    <?php 
      $numbers 
= array(123456789);
      
$random array_rand($numbers2
    
?>
    <label><?php print($random[0]." + ".$random[1]." ="); ?></label> <input id="spamCheck" type="text" name="spamCheck" /><br /><br />
    <input id="number1" type="hidden" name="number1" value="<?php print($random[0]); ?>" />
    <input id="number2" type="hidden" name="number2" value="<?php print($random[1]); ?>" />
  
    <input name="submit" type="submit" id="phplistSubmit" value="Submit" />
  </form>

</body>
</html>
y el ajax_phplist.js es este
Código PHP:
$(document).ready(function(){

   $(
"#messageBox").fadeOut(0);
 
  
//stuff to do when you click submit
  
$("#phplistSubmit").click(function(){
    
    
//pull in the variables to send
    
var email = $('#email').val();
    
//var emailConfirm = $('#emailConfirm').val();
    
var firstName = $('#firstName').val();
    var 
lastName = $('#lastName').val();
    var 
city = $('#city').val();
    
//var state = $('#state').val();
    //var zip = $('#zip').val();
    //var country = $('#country').val();
    
var spamCheck = $('#spamCheck').val();
    var 
number1 = $('#number1').val();
    var 
number2 = $('#number2').val();
    
    
//post our variables to phplist.php
    
$.post('phplist.php'
      
//{'submit' : 'Submit', 'email': email, 'emailConfirm' : emailConfirm, 'firstName' : firstName, 'lastName' : lastName, 'city' : city, 'state' : state, 'zip' : zip, 'country' : country, 'spamCheck' : spamCheck, 'number1' : number1, 'number2' : number2 }, 
       
{'submit' 'Submit''email'email'firstName' firstName'lastName' lastName'city' city,  'spamCheck' spamCheck'number1' number1'number2' number2 }, 
      function(
data){ 
        var 
splitString data.split("<div id='messageBox'>"); 
        var 
messages splitString[1].split("</div>"); 
        $(
"#messageBox").empty(); 
        $(
"#messageBox").append(messages[0]); 
        $(
"#messageBox").fadeIn(400); 
        
        
        
      } 
    ); 
    
    return 
false//override normal submit action
  
});

}); 
lo que no se haces es que cuando el $_GET['signup'] = 'succes' el form desaparezca y que el #messagebox se ponga en otra posicion

ponerlo en jquery se como hacerlo pero lo que no se es como pasar una variable al archivo de de ajax... no se si mer explico

pero he pensado en esto

Código PHP:
...
var 
messages splitString[1].split("</div>"); 
        $(
"#messageBox").empty(); 
        $(
"#messageBox").append(messages[0]); 
        $(
"#messageBox").fadeIn(400); 
        
            var 
mensajeok 
            
if (mensajeok()){
                $(
"form").hide();
                $(
"#messageBox").css("left","10px","top","94px");
                
            }
        
        
        
      } 
... 
con lo que consigo es que el form se esconda i que el #messagebox me lo mueva en la posición del form...
  #2 (permalink)  
Antiguo 26/11/2010, 11:29
Avatar de chicohot20  
Fecha de Ingreso: mayo-2009
Mensajes: 388
Antigüedad: 14 años, 10 meses
Puntos: 43
Respuesta: pasar datos a jquery con variable de php

La verdad no entiendo mucho, podrias simplificar tu codigo?, o poner un ejemplo sencillo de como lo quieres hacer?
  #3 (permalink)  
Antiguo 26/11/2010, 14:35
Avatar de engonga
Usuario no validado
 
Fecha de Ingreso: marzo-2002
Ubicación: Buenos Aires
Mensajes: 1.300
Antigüedad: 22 años, 1 mes
Puntos: 8
Respuesta: pasar datos a jquery con variable de php

no se como hacer que cuando

se cumpla esto

Código PHP:
//success message
if($_GET['signup'] == 'success'){
  
$message[] = array(
    
'text' => "<b>Tu correo electr&oacute;nico ha sido a&ntilde;adido a nuestro sistema</b>. Le enviaremos por correo electr&oacute;nico una solicitud para confirmar tu suscripci&oacute;n. Por favor, aseg&uacute;rate de hacer clic en el v&iacute;nculo en ese mensaje para confirmar su suscripci&oacute;n. Por favor, a&ntilde;ade [email protected] a tu libreta de direcciones.",
    
'class' => 'success',
    
'classok' => 'successok'
  
);
  

el ajax.jx se procese este is

Código PHP:
var messages splitString[1].split("</div>"); 
        $(
"#messageBox").empty(); 
        $(
"#messageBox").append(messages[0]); 
        $(
"#messageBox").fadeIn(400); 
        
            
            
// este if que lo que hace es esconder el form
            // y mover el mesagebox mas para la derecha
             
var mensajeok 
            
if (mensajeok()){
                $(
"form").hide();
                $(
"#messageBox").css("left","10px","top","94px");
                
            }
        
        
        
      } 

Etiquetas: ajax, pasar, php, variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:55.