1

I got a form here that I am trying to validate on my front page PHP file for my Wordpress site, whenever I click submit it takes me to a post "page not found", why is it even leaving the page? not sure what is wrong with my code, I am thinking the submit button must not be right, it shouldn't leave the page.

Maybe I'm not implementing PHP code the right way. The HTML form is at the beginning and PHP code at the end.

<form id="contact-form"  method="post">
                    <ul>
                        <li class="desc">Email</li>

                            <li><input placeholder="i.e.email@email.com" type="" name="email" id="form_email">
                            <span><?php echo $email_error ?></span></li>

                        <li class="desc">First Name</li>

                            <li><input type="text" name="firstName" id="form_firstName" ><span><?php echo $firstName_error ?></span></li>

                        <li class="desc" >Last Name</li>
                            <li><input type="text" name="lastName" id="form_lastName"><span><?php echo $lastName_error ?></span></li>

                        <li class="desc">Company Name</li>
                            <li><input type="text" name="companyName" id="form_companyName"><span><?php echo $companyName_error ?></span></li>

                        <li class="desc">Phone</li>
                            <li><input type="integer" name="phone" id="form_phone"><span><?php echo $phone_error ?></span></li>

                        <li><button name="name" value="submit" type="submit"></button><!--<a href="" id="sub"><img src="images/downloadbutton.png"><input type="hidden" name="submit" value="submit"/></a>--></li>

                    </ul>
                </form>
                <?php
            if(!empty($_POST['email']) && !empty($_POST['firstName']) && !empty($_POST['lastName']) && !empty($_POST['companyName']) && !empty($_POST['phone'])) {
$email = $_POST['email'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$companyName = $_POST['companyName'];
$phone = $_POST['phone'];

if(strlen($email)<5) {
    $email_error = '*';
}
elseif (strlen($firstName)<1) {
    $firstName_error = '*';
}
elseif (strlen($lastName)<1) {
    $lastName_error = '*';
}
elseif (strlen($companyName)<1) {
    $companyName_error = '*';
}
elseif (strlen($phone)<10) {
    $phone_error = '*';
}
else{
    echo " <ul>
            <li>email           : $email </li>
            <li>First Name      : $firstName</li>
            <li>Last Name       : $lastName</li>
            <li>Company Name    : $companyName</li>
            <li>Phone           : $phone</li>
          </ul>
          ";
}
}

else{
        $email_error = '*';
        $firstName_error = '*';
        $lastName_error = '*';
        $companyName_error = '*';
        $phone_error = '*';
}
?>
ArK
  • 20,698
  • 67
  • 109
  • 136
Frans B
  • 65
  • 1
  • 2
  • 11

1 Answers1

0

You can try by adding form action like

action='<?= get_permalink(page_id); ?>'

page_id = the page which process the form , may be its same page where form is displaying.

Thnx

Subrata
  • 175
  • 1
  • 2
  • 15