Viewed   99 times

I have this code in test.php.

  • When I access the script just by typing it, I want to see just the form
  • but when I click the form submit button, the next time the page loads, I want to see the form and some comment that says that the form has been submitted.

For some reason, even when I click submit, I don't get the message that it's posting. Anyone can explain why? and how can I get it to work.

<body>
    <form action="" method="post">
        <input type="text" id="inp" />
        <input type="submit" value="submit" />      
    </form>

    <?php
    if (isset($_POST['submit'])) {
        echo "posting";
    }

    ?>
</body>

 Answers

1

Give a name to the input:

<input type="submit" name="submit" value="submit" /> 
Tuesday, December 27, 2022
 
4

I would suggest something like:

<label for="user_firstname">Nume</label>
    <input id="user_firstname" type="text" name="user_firstname" value=<?(isset($_POST['user_firstname']) ? $_POST['user_firstname'] : ""; ?>>
    <? if (isset($errors['user_firstname'])): ?>
    <span class="error"><?= $errors['user_firstname']; ?></span>
<? endif; ?> 

You also had a typo in the $_POST["user_firstmane"] should be $_POST["user_firstname"] :)

Sunday, December 4, 2022
4

Probably you have element or JS object called form or submit somewhere, conflicting with the real form.

Most safe way is using document.getElementById:

<select onchange="SubmitForm('orderbyfrm');">

And the JavaScript:

function SubmitForm(formId) {
    var oForm = document.getElementById(formId);
    if (oForm) {
        oForm.submit(); 
    }
    else {
        alert("DEBUG - could not find element " + formId);
    }
}

Further debugging with good old alert.. instead of the alert("DEBUG ... have this:

var sDebugInfo = "found " + document.forms.length + " forms: n";
for (var i = 0; i < document.forms.length; i++) {
    var curForm = document.forms[i];
    sDebugInfo += "name: " + curForm.name + ", id: " + curForm.id;
    sDebugInfo += "n";
}
alert(sDebugInfo);

Depending on what you get, debug should continue.

Thursday, September 22, 2022
2

A div is not a form element. There is no this.form for it.

You can still do document.forms.form.submit() (.form since you have name="form")

Saturday, September 10, 2022
 
4

Try this code

$("#send").on("click", function(e) {
e.preventDefault();
$.ajax({
            type: "POST",
            url: "ads_process.php",
            //Specify the datatype of response if necessary
            data: $("#ads").serialize(),
            success: function(data){
                if(data == "true") {
                    $("#ads").fadeOut("fast", function(){
                        //$(this).before("<p><strong>Success! Your message has been sent, thanks!</strong></p>");
                        setTimeout("$.ads.close()", 2000);
                        });
                    }
                }
            });
        });
Thursday, December 15, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :