Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple PHP submit form not working

Tags:

People also ask

Why submit button is not working in PHP?

You need a form surrounding the input. Save this answer. Show activity on this post. You have no form tag and even if you did it would need the method="post" attribute.

How to submit a form to itself in PHP?

The proper way would be to use $_SERVER["PHP_SELF"] (in conjunction with htmlspecialchars to avoid possible exploits). You can also just skip the action= part empty, which is not W3C valid, but currently works in most (all?) browsers - the default is to submit to self if it's empty.

What is_ PHP_SELF?

The $_SERVER["PHP_SELF"] is a super global variable that returns the filename of the currently executing script. So, the $_SERVER["PHP_SELF"] sends the submitted form data to the page itself, instead of jumping to a different page. This way, the user will get error messages on the same page as the form.

How to use PHP_SELF function?

PHP_SELF is a variable that returns the current script being executed. You can use this variable in the action field of the form. The action field of the form instructs where to submit the form data when the user presses the submit button. Most PHP pages maintain data validation on the same page as the form itself.


Just making a simple submit form and can't seem to get it working.

It won't even report errors which is odd.

Checked the php.ini and that all seems fine too.

HTML:

<form id="submit-form" action="receiving.php" method="POST">
        <h3>Submit a Link</h3>
        <fieldset>
            <table>
                <tr>
                    <td><label for="name">You</label></td>
                    <td><input id="name" name="name" type="text" placeholder="Your Twitter or Blog ect." /></td>
                </tr>
                <tr>
                    <td><label for="submit-links">Link(s)</label></td>
                    <td><input id="sumbit-links" name="submit-links" type="text" placeholder="" required="" /></td>
                </tr>
                <tr>
                    <td><input name="submit" type="submit" value="SUBMIT" /></td>
                </tr>
            </table>
        </fieldset>
    </form>

receiving.php:

<?php 
error_reporting(-1);
$name = $_POST['name']; 
$submit-links = $_POST['submit-links']; 
if(isset($_POST['submit'])){
 $from_add = "[email protected]"; 
 $to_add = "[email protected]"; 
 $subject = "Your Subject Name";

 $message = "Name:$name \n Sites: $submit-links";

 $headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion()

 if(mail($to_add,$subject,$message,$headers)){
    $msg = "Mail sent";
 } 
}
print "<p>Thanks $name</p>";
?>

Any help would be much appreciated :)