I am creating a sms confirmation system for my site... so i have one form for taking the user input name and mobile number when the user submits, data sent via jquery ajax to a php file send_sms.php random code is sent to mobile but the problm is getng json callback parseerror condition pls help me...pls go through the code..thanks in advance :)
HTML FORM:
<form name="stage1" id="stage1" action="process_sms.php" enctype="multipart/form-data" method="POST">
<div id="response1"><!--this text will be disappeared --></div>
<label for="name">Name:</label><input type="text" name="name" id="name" />
<label for="mobileno">Mobile No:</label><input type="text" name="number" id="number" maxlength="10" />
<br/><br/>
<input type="submit" name="submit1" id="submit1" value="Step1-Send Code" />
</form>
jquery code
$(document).ready( function() {
$('form #response1').hide();
var sub_total = $('span .price_check').text();
$('#submit1').click(function(e) {
e.preventDefault();
//get the values
var valid = '';
var required = 'is required.';
var name = $('form #name').val();
var number = $('form #number').val();
var confirm_code = $('form #confirm_code').val();
//checking
if(name = '' || name.length <=2) {
valid = '<p>Your Name ' + required + '</p>';
}
if(number = '' || number.length > 10 || number.length < 10) {
valid += '<p>Your Number ' + required + '</p>';
}
// let the user know if there are erros with the form
if(valid != '') {
$('form #response1').removeClass().addClass('error').html('<strong><p>Please correct the below errors.</p><strong>' + valid).fadeIn('fast');
} else {
$('form #response1').removeClass().addClass('processing').html('<p>processing... </p>').fadeIn('fast');
var formData = $('form').serialize();
submitForm(formData);
}
});
});
function submitForm(formData) {
$.ajax ({
type: 'POST',
url: 'process_sms.php',
data: formData,
dataType: 'json',
cache: false,
timeout: 7000,
success: function(data) {
$('form #response1').removeClass()
.addClass((data.error === true) ? 'error' : 'success')
.html(data.msg).fadeIn('fast');
if ($('form #response1').hasClass('success')) {
setTimeout("$('form #response1').fadeOut('fast')", 5000);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('form #response1').removeClass()
.addClass('error')
.html('<p>There was an '+ errorThrown +
' </b>error due to a '+ textStatus +
' condition.</p>').fadeIn('fast');
},
complete: function(XMLHttpRequest, status) {
$('form #stage1')[0].reset();
}
});
};
the Next one id the PHP form :::
it includes the curl_init function to post the data to the sms gate-way, when i inlcuded the code it started showing the error parseerror condition! pls help me..next form will continues with confirmation yet to do that any idea for that to start with..appreciated thanq.
sms_code.php
<?php
//sleep(3);
$name = trim($_POST['name']);
$number = trim($_POST['number']);
$char_set = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
$confirm_code = substr(str_shuffle($char_set), 0, 6);
$error_msg = '';
if(empty($name)) {
$error_msg .= "<p>Please provide your Name.</p>";
}
if(empty($number)) {
$error_msg .= "<p>Valid mobile Number is Required.</p>";
}
if(!empty($name) && !empty($number) && empty($error_msg)) {
include"dbcon.php";
$get = mysql_query("INSERT INTO members (username, mobile, confirm_code, verified) VALUES('$name', '$number', '$confirm_code', '0')");
$username = "myusername";
$password = "mupaswd";
$sender_id = "my_id";
$message = "Helo".'$name'.", confirm code is ".$confirm_code;
$vars = "user=".$username."&password=".$password."&msisdn=91".$number."&sid=".$sender_id."&msg=".$message."&fl=0";
$curl = curl_init('http://smslane.com/vendorsms/pushsms.aspx');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $vars);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
curl_close($curl);
} else {
$error_msg .= "<p>failed to send sms, pls try Again!</p>";
}
if(!empty($error_msg)) {
$return['error'] = true;
$return['msg'] = "<h4><p>Oops... Request was successful but fields are not correct.</p></h4>".$error_msg;
echo json_encode($return);
exit();
} else {
$return['error'] = false;
$return['msg'] = "<p>Confirm code sent successfully to ".$number.".</p>";
echo json_encode($return);
}
?>