Pallavipradeep
Pallavipradeep

Reputation: 101

How to call php validation file to html file when clicked on submit button

Am trying to call PHP validation file into a HTML file. Could any one suggest me how to call that php file when click on submit button.

Sample html code:

<head>
    <style>
        .error {color: #FF0000;}
    </style>
</head>
<body style="background-color:#F2F2F2">
    <form name="htmlform" method="post" onsubmit="\test_form.php">
        <table width="550px" table align="center" frame="box" height="80%" style="margin-top:25px;margin-bottom:25px; background-color:#ffffff;border-radius:5px;"></tr>
            <tr>
                <th colspan="2">
                    <h3  align="center">Write to Us</h3>
                    <hr>
                </th>
            </tr>
            <tr>
                <td valign="top">
                    <label for="name">Name </label>
                </td>
                <td valign="top">
                    <input  type="text" name="name" maxlength="50" size="30">
                    <span class="error">* <?php echo $nameErr;?></span>
                </td>
            </tr>
            <tr>
                <td valign="top">
                    <label for="email">Email Address </label>
                </td>
                <td valign="top">
                    <input  type="text" name="email" maxlength="80" size="30">
                    <span class="error">* <?php echo $emailErr;?></span>
                </td>
            </tr>
            <tr>
                <td valign="top">
                    <label for="telephone">Telephone Number</label>
                </td>
                <td valign="top">
                    <input  type="text" name="telephone1" maxlength="30" size="30">
                </td>
            </tr>
            <tr>
                <td valign="top">
                    <label for="message">Message </label>
                </td>
                <td valign="top">
                    <textarea  name="message1" maxlength="1000" cols="25" rows="6"></textarea>
                    <span class="error">* <?php echo $messageErr;?></span>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align:center;">
                    <input type="submit" value="Submit" onclick="$.fancybox.close()">
                </td>
            </tr>
        </table>
    </form>
</body>

and PHP code is as follows:

<?php
    if (isset($_POST['submit']))
    {
        if (empty($_POST["name"]))
            {$nameErr = "Name is required";}
        else
            {$name =test_input($_POST["name"]);}

        if (empty($_POST["email"]))
            {$emailErr = "Email is required";}
        else
            {$email = test_input($_POST["email"]);}

        if (empty($_POST["telephone1"]))
            {$telephone1 = "";}
        else
            {$telephone1 =test_input($_POST["telephone1"]);}

        if (empty($_POST["message1"]))
            {$messageErr = "Message is required";}
        else
            {$message1 = test_input($_POST["message1"]);}

        if(isset($name) && isset($email) && isset($message1))
        {
            echo "<h2>Your Input:</h2>";
            echo $name;
            echo "<br>";
            echo $email;
            echo "<br>";
            echo $telephone1;
            echo "<br>";
            echo $message1;
            $recipient = "[email protected]"; ///  Your Email address
            if (isset($_POST['email']))
            {
            //Send Mail To Webmaster
                $email = $_POST['email'] ;
                $subject = 'Feedback Form';
                $message =  $name . ' has been subscribed to your website.';
                mail("$recipient", $subject, $message, "From:" . $recipient);
            }
        }
    }
    function test_input($data)
    {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    }
?>

It is not accepting when I keep php code into html file and save it as php and execute in word press.

Upvotes: 0

Views: 1033

Answers (2)

Azrael_404
Azrael_404

Reputation: 446

what is the path of the first and second page ?

use this instead : http://jqueryvalidation.org/documentation/

$().ready(function() {
// validate form on keyup and submit
$("#htmlform").validate({
    rules: {
        name: {
            required: true,

        },
        email: {
            required: true,
            email:true
        }....

}
});

For WP take a look to this , it's might be usefull , you don't need to code a lot , just config in WP

Upvotes: 0

CS GO
CS GO

Reputation: 912

<form method="post" onsubmit="\test_form.php">

change it to:

<form method="post" action="test_form.php">

Upvotes: 3

Related Questions