Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6252929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:53:50+00:00 2026-05-24T13:53:50+00:00

Having trouble getting a form using PHP, JQuery Form plugin, and JQuery Validate plugin

  • 0

Having trouble getting a form using PHP, JQuery Form plugin, and JQuery Validate plugin to work as expected. I’m using Validation plugin v 1.8.1, so it is not due to the bug with dataType: 'json', being read as jsonp. Below is the html:

<?php require_once('includes/initialize.php'); ?>
<?php require_once('layouts/header.php'); ?>
<body>
    <div class="container_12">

        <div class="grid_4" id="form">

            <form action="actions/register.php" method="POST" class="cmxform" name="frmPrntRgstr" id="frmPrntRgstr">
        <p>
                <label>Desired Username:</label>
                <input type="text" name="userName" id="userName" value="" />
        </p>
            <div class="clear"></div>
        <p>
                <label>Password:</label>
        <input type="password" name="Pwd" id="Pwd" />   
        </p>
            <p>
                <label>Confirm Password:</label>
                <input type="password" name="confirmPwd" id="confirmPwd" />
            </p>
            <div class="clear"></div> 
            <p> 
                <label>First Name:</label>
                <input type="text" name="firstName" id="firstName" value="" />
            </p>
            <div class="clear"></div>
            <p>
                <label>Last Name:</label>
                <input type="text" id="lastName" name="lastName" value="" />
            </p>
            <div class="clear"></div>
            <p>
                <label>Email Address:</label>
                <input type="text" id="email" name="email" value="" />
            </p>
            <div class="clear"></div>
            <p> 
                <label>Cell Phone:</label>
                <input type="text" id="cellPhone" name="cellPhone" value="" />
            </p>
            <p>
                <label>Home Phone:</label>
                <input type="text" id="homePhone" name="homePhone" value="" />
            </p>
            <input type="hidden" id="role" name="role" value="2" />
            <input type="hidden" id="approved" name="approved" value="0" />
            <input type="hidden" id="school" name="school" value="0" />
            <p>
                 <input class="submit" type="submit" id="regUser" value="Submit" />
            </p>
        </form>
        <p id="frmPrntRgstrRspns" style="display: none;">A Response goes here.</p>
    </div>
</div>

Simplified version of register.php without error checking:

<?php require_once('../includes/initialize.php'); ?>
<?php require_once('../layouts/appheader.php'); ?>

<?php
    if (isset($_POST["userName"])) {
    $auser = new User();
    $auser->userName = $_POST['userName'];
    $auser->hshdPwd = sha1($_POST['Pwd']);
    $auser->firstName = $_POST['firstName'];
    $auser->lastName = $_POST['lastName'];
    $auser->email = $_POST['email'];
    $auser->cellPhone = $_POST['cellPhone'];
    $auser->homePhone = $_POST['homePhone'];
    if(!is_null($_POST['school'])) {
         $auser->school = $_POST['school'];
    } else {
    $auser->school = "0";   
    }
    $auser->prelim_role = $_POST['role'];
    $auser->approved = $_POST['approved'];
    if($auser->create()) {
    $abc = array('response'=>"Request successfully submitted"); ;
    } else { 
    $abc = array('response'=>"Errors.");
    } 
return ?> 
    <script type="text/javascript"> 
        var resp2 = '<?php echo json_encode($abc, JSON_FORCE_OBJECT); ?>';
    </script>
    <?php
    }
    ?>

Below is the register.js file:

$(document).ready(function() { 
$("#frmPrntRgstr").validate({
                    rules: {
                            firstName: "required",
                            lastName: "required",
                            userName: {
                                required: true,
                                minlength: 6
                            },
                            Pwd: {
                            required: true,
                            minlength: 6
                            },
                            confirmPwd: {
                                required: true,
                                minlength: 6,
                                equalTo: '#Pwd'
                            },
                            homePhone: {
                                required: true,
                            },
                            cellPhone: {
                                required: true,
                            },
                            email: {
                                required: true,
                                email: true
                            },
                            },
                            messages: {
                            firstName: "Please enter your firstname",
                            lastName: "Please enter your lastname",
                            userName: {
                                required: "Please enter a username",
                                minlength: "Your username must consist of at least 6 characters"
                            },
                            hshdPwd: {
                                required: "Please provide a password",
                                minlength: "Your password must be at least 6 characters long"
                            },
                            confirmPwd: {
                                required: "Please provide a password",
                                minlength: "Your password must be at least 6 characters long",
                                equalTo: "Please enter the same password as above"
                            },
                            email: "Please enter a valid email address",
                            },
                            submitHandler: function(form) {
                                $("#frmPrntRgstr").ajaxSubmit({
                                                        dataType: 'json',
                                                    success:    processJson,
                                                        })
                            }
});
                function processJson() {
                        var resp3 = $.parseJSON(resp2); 
            $("#frmPrntRgstr").slideUp("normal", function() {
                            $(resp3.response).appendTo("#frmPrntRgstrRspns", function() {
                       $("#frmPrntRgstrRspns").slideDown("normal");
                                 })
            })
                }
});

I have tried changing content type to “application/json” in all files. When I remove dataType: 'json' and have a success function like $("#frmPrntRgstr").slideUp("normal", function () { $("#frmPrntRgstrRspns").slideDown("normal") }); everything works fine. When I add dataType: 'json', even when I’m not trying to parse the json server response or use it in the success function, the new user will be inserted into the MySQL database, but the client-side sees no response. Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:53:51+00:00Added an answer on May 24, 2026 at 1:53 pm

    This is what your script returns:

    <script type="text/javascript"> 
        var resp2 = '<?php echo json_encode($abc, JSON_FORCE_OBJECT); ?>';
    </script>
    

    This is not JSON, it’s a fragment of HTML that contains a script tag with a javascript variable declared inside of it.

    A JSON response would look like <?php echo json_encode($abc); ?> alone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting django's django.contrib.localflavor.au.forms to validate my form input. I have tried
i'm having trouble getting the date to be imported into mysql from my form.
I am having trouble getting a success: function(){} working - the ajax code I
I've just written my first Perl module and am having trouble getting it to
I'm having trouble inserting data into a table. I have the following tables: track
I'm creating an online poll from scratch which will be held in a database.
I had recently asked a related question In C# how do I have a
I am trying to learn JDO (and at the same time its GAE and
I'm trying to draw a gradient in a rectangle object, with a given angle
I am new to AES encryption but trying to build a solution which: Accepts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.