K Ahir
K Ahir

Reputation: 395

JSON Success / Error message displaying on local server but not on godaddy server

I have PHP 5.4.45 on my local server and PHP 5.4.45 on Godaddy server.

contact_p.php page sends all success/error messages properly for all valid/invalid data entered on contact.php form page. So I am able to print them on contact.php page.

Contact inquiry is inserted successfully into database table on both local and godaddy server, but success/error message is only displaying on my local web server and not on GoDaddy server.

So what may be the reason for this strange issue? Please advise so I can make necessary changes In my script and/or on server.

contact.php

<form name="contactForm" id="contactForm" novalidate>
<div class="control-group form-group">
    .
    .
    other fields like Name, Mail, Phone, captcha etc
    .
    .
    <div id="success"></div>
    <!-- For success/fail messages -->
    <button type="submit" class="btn btn-primary">Send Message</button>
</div>
</form>

contact.js

$(function() {

$("#contactForm input,#contactForm textarea ,#contactForm select").jqBootstrapValidation({
    preventSubmit: true,
    submitSuccess: function($form, event) {
        event.preventDefault(); 
        var subject = $("select#subject").val();
        var name = $("input#name").val();
        var phone = $("input#phone").val();
        var email = $("input#email").val();
        var message = $("textarea#message").val();
        var secretcode = $("input#secretcode").val();

        $.ajax({
            url: "./user/contact_p.php",
            type: "POST",
            data: {
                subject: subject,
                name: name,
                phone: phone,
                email: email,
                message: message,
                secretcode: secretcode
            },
            cache: false,

            success: function(data) 
            {
                //alert(data);
                var $ResponseText_L=JSON.parse(data);
                if($ResponseText_L.status == 'SUC')
                {
                    // Success message
                    $('#successL').html("<div class='alert alert-success'>");
                    $('#successL > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                    .append("</button>");
                     $('#successL > .alert-success').append("<strong> " + $ResponseText_L.message + " </strong>");
                    $('#successL > .alert-success').append('</div>');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                }

                else if($ResponseText_L.status == 'ERR')
                {
                    // Fail message
                    $('#successL').html("<div class='alert alert-danger'>");
                    $('#successL > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                        .append("</button>");
                    $('#successL > .alert-danger').append("<strong> " + $ResponseText_L.message + " ");
                    $('#successL > .alert-danger').append('</div>');
                }
            },
        })
    },
    filter: function() {
        return $(this).is(":visible");
    },
});

$("a[data-toggle=\"tab\"]").click(function(e) {
    e.preventDefault();
    $(this).tab("show");
});
});

/*When clicking on Full hide fail/success boxes */
$('#l_name').focus(function() {
    $('#successL').html('');
});

contact_p.php

$str_name = "";
if (isset($_POST["name"])) { $str_name = trim($_POST["name"]); }
$str_email = "";
if (isset($_POST["email"])) { $str_email = trim($_POST["email"]); }
$str_phone = "";
if (isset($_POST["phone"])) { $str_phone = trim($_POST["phone"]); }
$str_message = "";
if (isset($_POST["message"])) { $str_message = trim($_POST["message"]); }
$str_subject = "";
if (isset($_POST["subject"])) { $str_subject = trim($_POST["subject"]); }
$str_secretcode = "";
if (isset($_POST["secretcode"])) { $str_secretcode = trim($_POST["secretcode"]); }

if( empty($str_name))
{
    $response['status']='ERR';
    $response['message']= "Please enter full name!";
    echo json_encode($response); 
    return;
}
if( empty($str_message))
{
    $response['status']='ERR';
    $response['message']= "Please enter message!";
    echo json_encode($response); 
    return;
}
if( empty($str_subject) )
{
    $response['status']='ERR';
    $response['message']= "Please select subject!";
    echo json_encode($response); 
    return ;
}
if( empty($str_secretcode) || $_SESSION['image_secret_code'] != $str_secretcode )
{
    $response['status']='ERR';
    $response['message']= "Invalid Secret Code!";
    echo json_encode($response);
    return;
}

$str_query_insert="INSERT INTO t_contact_inquiry(subjectpkid, fullname, emailid, phone, description)";
$str_query_insert.=" VALUES(".$str_subject.",'".$str_name."','".$str_email."','".$str_phone."','".$str_message."')";    
ExecuteQuery($str_query_insert);    


$response['status']='SUC';
$response['message']="Your contact inquiry has been submitted";
echo json_encode($response);
return;

Upvotes: 0

Views: 106

Answers (1)

kator
kator

Reputation: 959

Your code seems pretty okay. Although it appears the $form variable in contact.js hasn't been defined. Could you verify?

Edit: Sorry, I didn't study your code much before my first answer. I think the issue is probably in your if() statement. Try trimming your $ResponseText_L.status to make sure there are no spaces within. Try if($ResponseText_L.status.trim() == 'SUC') { /display success message/ } else if($ResponseText_L.status.trim() == 'ERR') { /display error message/ } . Hope this helps!

Upvotes: 0

Related Questions