26/11/2010, 03:57
|
| Usuario no validado | | Fecha de Ingreso: marzo-2002 Ubicación: Buenos Aires
Mensajes: 1.300
Antigüedad: 22 años, 9 meses 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($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $url ); // enable http posts .... curl_setopt ($ch, CURLOPT_POST, 1); // set form posting .... curl_setopt ($ch, CURLOPT_POSTFIELDS,$postfields); //output returned to a variable curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); // include server header responses .. curl_setopt($ch, CURLOPT_HEADER, false); $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álido</b> Porfavor introduce email válido y prueba de nuevo.", 'class' => 'error' ); } else { $message[] = array( 'text' => "<b>Oops!! algo salió 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ónico ha sido añadido a nuestro sistema</b>. Le enviaremos por correo electrónico una solicitud para confirmar tu suscripción. Por favor, asegúrate de hacer clic en el vínculo en ese mensaje para confirmar su suscripción. Por favor, añ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ó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(1, 2, 3, 4, 5, 6, 7, 8, 9); $random = array_rand($numbers, 2) ?> <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... |