Hello. I created a form, filled one field, I want this page to refresh and display what I filled out. Here is a little code:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="" method="POST" class="info-profile"> <input type="text" name="name" value="ROBERT SMITH"> <input type="submit"> </form> </body> <?php if (!empty($_POST["name"])) { echo " Получены новые вводные: имя - ".$_POST["name"];} else { echo "Переменные не дошли. Проверьте все еще раз."; } ?> </html> 

The problem is that this code works perfectly on LAN, but on the WordPress page I click send and it gives a message - this page was not found. How to be?

  • Though I don't know php well, but I can't see the call alone? And in general, any function? - Oma
  • If there is nothing in action, then he calls himself. Why functions, echo should output what we enter in the field. - Stanislav
  • @ Stanislav check the correctness of the paths. - Vadizar
  • The paths are correct, plus he calls himself. - Stanislav
  • In which file do you write the code? - Kirill Korushkin

2 answers 2

The assumption that any php code will be executed on the html page is incorrect.

You need to create a .php file. In him:

 <?php ?> <form action="" method="POST" class="info-profile"> <input type="text" name="name" value="ROBERT SMITH"> <input type="submit"> </form> <?php if (!empty($_POST["name"])) { echo " Получены новые вводные: имя - ".$_POST["name"];} else { echo "Переменные не дошли. Проверьте все еще раз."; } ?> 

See how it works on my test site: http://test.kagg.eu/so/632157.php

UPDATE

As a result of clarifying the issue, it turned out that the author created the WordPress page and set up its own php template for it. In the php file of the template there is the following fragment:

 ?> <form action="" method="POST" class="info-profile"> <input type="text" name="name" value="ROBERT SMITH"> <input type="submit"> </form> <?php if (!empty($_POST["name"])) { echo " Получены новые вводные: имя - ".$_POST["name"];} else { echo "Переменные не дошли. Проверьте все еще раз."; } ?> 

Pressing the button displays error 404.

This is because there is a list of reserved words in WordPress that should not be present in GET and POST requests. The word name is in this list.

Here’s how the template file for the page should look like:

 <?php /* Template Name: cv */ ?> <form action="" method="POST" class="info-profile"> <input type="text" name="cv_name" value="ROBERT SMITH"> <input type="submit"> </form> <?php if ( isset($_POST['cv_name']) ) { echo " Получены новые вводные: имя - " . $_POST["cv_name"]; } else { echo "Переменные не дошли. Проверьте все еще раз."; } ?> 

View a working example here .

  • combined the questions - Nick Volynkin
  • @NickVolynkin thanks - KAGG Design

Try

 action="<?php bloginfo('template_directory');?>"