jQuery animation before submitting the form

0

I have this code, the animation happens but the redirect to the next page ( work.php ) does not.

That is, you are not entering the if (isset($_POST... condition. If I comment on the piece of code responsible for the animation the redirection already happens, but that's not what I want:

index.php:

if (isset($_POST['submit'])) {

    $firstName = htmlentities($_POST['name']);
    $firstName = str_replace(array('.', ',', ';', '?', '/', '|', '(', ')', 'º', '+', '#', '$', '@', "'", '"'), '' , $firstName);
    $firstName = trim(ucwords($firstName));

    if(!empty($firstName)) {
        $user->saveCookie($firstName);
    }

    header('Location: work.php');
}
require_once('includes/head.php');
?>
<body onunload="">
    <div id="wrapper">
.....
<form action="" method="POST">
    <input name="name" type="text" autocomplete="off">
    <input type="submit" name="submit">
</form>
.....
</html>

js.js:

$('input[type="submit"]').click(function(event) {
        event.preventDefault();

        $('#footer').css({
            "position":"absolute",
            "bottom": "5px"
        });
        $('#wrapper').animate({
            "margin-top": "-1000px"
        }, 700, function(){
            $('form').submit();
        });
    });
    
asked by anonymous 27.08.2014 / 10:52

2 answers

0

I've been able to resolve, 'submit' is a reserved javascript word so the 'name' of the 'input' type 'can not be' submit ', it conflicts in some way with the' submit ' ) 'from javascript:

1st change: HTML

<form action="" method="POST">
    <input name="userName" type="text" autocomplete="off">
    <input type="submit" name="nameCookie">
</form>

After this it appears that the form is submitted because it is made a reload to the page but continues without being processed by the 'if (isset (...)' condition because redirection does not occur. There was somehow some sort of conflict with the javascript part, so I changed the isset argument, so instead of being the 'name' of 'input [type =' submit '] "(nameCookie), passed to be the 'name' of the 'input [type =' text '] "(userName):

2nd change: PHP

if (isset($_POST['userName'])) {
    $firstName = htmlentities($_POST['userName']);
    ...
    if(!empty($firstName)) {
        $user->saveCookie($firstName);
    }
    header('Location: work.php');
}

I did not make any changes to js.js.

PS: I do not know (if anyone knows) explain the technical reasons for this second change to be necessary, but it worked.

    
29.08.2014 / 01:17
0

Clicking "Yours" is not running this code. The code that is running is:

$('#formName').click(function(){
            $(this).css({
                "text-decoration": (underline = !underline) ? "none" : "underline"
            })
            $('form, h2, p').fadeToggle(500);
            $('h3').stop().animate({
                "top": (down = !down) ? "330px" : "290px"
            }, 500);
            $('form input').focus();
        });
    
27.08.2014 / 13:34