.ajax() Data Passed to PHP is the PHP script?

Than errors needs to be an array of strings instead of just a string.

1 Like

As said by @oddz above, the problem is your JS script expects array in $response['errors'] but you send string instead:

$response['errors'] = "That e-mail address already exists!";

rewrite that line:

$response['errors'][] = "That e-mail address already exists!";
1 Like

Yes, this is the answer! It is to have the value set to an array. Thanks!

Now, the last problem I have is returning to the original state of .signupstep1 smoothly after the user submits the form successfully.

Right now on the test page, the .signupstep1 shows up way too soon, even after I tried putting a delay on .signupstep1 and despite putting this in its own function, it still displays too soon. The other thing is that I have a block of code for disabling the input fields on the first form, and that isn’t working (maybe my JS doesn’t target the form elements correctly). The values are correctly changed to “Thanks!” and the input is changed to the e-mail supplied, though. That’s another in another line in testSecondResults().

Here’s some of the script:

function returnToFirstStep {
    $(".signupstep3").slideUp(800);
    $(".signupstep1").delay(4000).fadeIn(1000);
    $("#form1 input").each(function(){
        $(this).prop("disabled", "disabled");
    });
    $("#submit").val('Thanks!');
    $(".joinlist p").text("Join the Mailing List!");
}

  function testSecondResults(data){
    if (data['validation'] == "pass"){
        $(".signupstep2").hide();
        $(".signupstep3").show().delay(4000).slideUp(1200);
        $(".joinlist p").text('');
        var name = $("#name").val();
        var email = $("#confirmemail").val();
        $("#username").append(name);
        $("#emailaddr").append(email);
        returnToFirstStep();

“.joinlist p” text is changed because the transitions re-position the primitive text on top of the first graphics. It’s a visual fix. You’ll notice that after successful submission, you’ll see the primitive text pop up/blink on top of the first form.

Almost done,

Ty

  1. Use callback for slideUp:

    $(“.signupstep3”).slideUp(800, function(){
    // this function will be executed
    // when slideUp is done
    $(“.signupstep1”).fadeIn(1000);
    });

  2. prop() requires boolean:

    $(“#form1 input”).prop(“disabled”, true);

also there is no need to use .each()

Does it work for you now? I have refreshed the page and re-uploaded several times, but I still don’t see a change. Maybe I should clear my cache before trying again.

The change:

    if (data['validation'] == "pass"){
        $(".signupstep2").hide();
        $(".signupstep3").show().delay(4000).slideUp(1200, function(){
            $(".joinlist p").text('');
            $(".signupstep1").fadeIn(1000, function(){
                $(".joinlist p").text("Join the Mailing List!");
            });
            $("#form1 input").prop("disabled", true);
        });
        $("#submit").val('Thanks!');
        var name = $("#name").val();
        var email = $("#confirmemail").val();
        $("#username").append(name);
        $("#emailaddr").append(email);

edit: My web server appears to be going crazy because the PHP script is running only. The JS has stopped. Weird?

I found an error in the JS, and now I seem to be back on track. I should be able to handle it now.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.