jeudi 12 janvier 2017

HTML form and WWW prefix issue

When I use form action URL with 'www' prefix, by pressing the submit button (or enter key) the form does not work: submits but won't send any variables. It does work, however, with JS submit by clicking the magnifier, even though JS code does not affect the URL (at least as far as I know).

When I remove 'www' it works both ways. Any idea what the reason is behind this?

http://ift.tt/2iLG42f

I made a gray div above the form to display POST variables.

Here's my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"     "http://ift.tt/nYkKzf">
<html xmlns="http://ift.tt/lH0Osb">
<html>
<head>
<title>Bonjour! :)</title>
<meta http-equiv="content-language" content="hu" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="tabs.css">
<link rel="shortcut icon" href="images/favicon.ico?v=1.2">
<script>
    function addElementAndSubmitForm(formName,actionUrl,elName,elValue) {
        var form = document.forms[formName];
        form.action = actionUrl;
        var el = document.createElement("input");
        el.type = "hidden";
        el.name = elName;
        el.value = elValue;
        form.appendChild(el);
        form.submit();
}
</script>
</head>
<body>
    <div id="page-wrap">
        <form name="myForm" method="POST" action="http://ift.tt/2iLG42f">
            <div id="debug" style="border:solid 1px black;padding:10px;margin:10px;background:#ccc;color:#555;width:96%">
            <font style="font-weight:bold">POST vars:</font>
            <?php
                if( count($_POST) > 0 ) {
                    echo "<br/><span style=\"padding-left:4px\"> ";
                    print_r($_POST); echo "</span>";
                }
            ?>
            </div>
            <div style="float:left;">
                Chercher un mot: <input type="text" id="cherfield" name="chercher" />
                <img style="padding: 0 5px; margin: 0 0 -8px 0;" src="images/chercher.jpg" onClick="javascript:addElementAndSubmitForm('myForm','#','chercher',document.getElementById('cherfield').value);"/>
                <br />
                <input type="submit" value="envoi" />
            </div>
            <input type="hidden" name="hidden_input" value="whatever">
        </form>
    </div>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire