How to make the required attribute for input work in older versions of IE? So, how can I get required to work in older versions of IE.

One of the most fun and useful features of PHP is including another file. For example, a website has a top menu, a bottom menu, and between them the page content itself. And, for example, on 10 pages of the site the bottom menu is used. At some point, changes needed to be made to it. In html you would manually make changes in each individual file, but php allows you to significantly simplify working with the site! The code for the bottom menu can be contained in a separate file, and on each of the 10 pages you can simply include this separate file! That is, all changes now need to be made only to the file with the menu, and on 10 others it will be displayed with changes.

The meaning of connecting in php in simple Russian language:

File 1.php
Top Menu

File 2.php
Lower menu

example.php file
Connect File 1.php
Page content
Connect File 2.php

As a result of processing the example.php file, it will be displayed
Top Menu
Page content
Lower menu
Accordingly, in order to change anything in the bottom menu, you need to make changes only in the 2.php file

Path to file The file is connected according to the path specified for the file. There are two path options: relative and absolute. Relative - this is an indication of the path to the connected file relative to the file with the connection instructions. Absolute - specifying the full path to the included file.

PHP code

// example of a relative path
include "include/your_file.php"; // the file is in the include folder, which is located in the same directory as the connection file

// example of an absolute path
include $_SERVER["DOCUMENT_ROOT"]."/include/your_file.php"; // $_SERVER["DOCUMENT_ROOT"] - indicates the root directory of the site

include and include_onceinclude() are constructs designed to include files in PHP script code during execution of the PHP script. When processing the code, the instruction is replaced with the contents of the attached file. I suggest looking at an example right away.

Let's look at how include works using two files as an example: index.php and text.php . For simplicity of work, let's assume that they are located in the same directory.

PHP code (index.php file)

Echo "Plain text contained in the main file";
include "text.php"; // include the contents of the text.php file

?>
PHP code (text.php file)

Echo "Text contained in the included file";

?>
The result of running the index.php file will be:

Plain text contained in the main file
Text contained in the included file
Is it really convenient? Now, by changing the contents in the text.php file, the result of index.php will be completely different!

Now let's talk about another construct - include_once. It works exactly the same as include, only created later and for those cases when the file cannot be re-included. For example, you are afraid that as a result of an error you may connect a file 2 or more times, which will affect the page not working correctly and receiving a corresponding error message.

PHP code

Include_once "text.php"; // the text.php file will be included only once

// reconnections below will not be taken into account and displayed
// and it will not cause an error message to be displayed
include_once "text.php"; // nothing will happen

require and require_once The require and require_once instructions work identically to include and include_once with the exception of only one feature - if the included file is not found, script execution will be stopped (the script will no longer be read), while include and include_once simply print warning and continue further execution of the script. If include or require does not work To understand the reasons why include does not work, I suggest checking everything step by step. No matter how clear and superficial the points below may be, check everything from the very beginning

1. Check if your server and php are working, and if any php code on the site is working at all
2. Check if the include file exists
3. Check if the file name and extension are entered correctly in the connection
4. Make sure that the included php file is actually located at the address you specified
5. Try to specify not a relative path, but an absolute path (full path to the file).

Example PHP Code

Include "http://www.example.com/include/your_file.php";

// DOCUMENT_ROOT - denotes the root directory of the resource
include $_SERVER["DOCUMENT_ROOT"]."/include/your_file.php";

6. If your file does not connect and no error is displayed, then in the directory with the file you are connecting, create a .htaccess file with the following contents

Php_flag display_errors On
or in the php file, before connecting, insert the following line

Error_reporting(E_ALL);
Both settings will force errors to be displayed

Thank you for your attention!

For any web developer, there is currently no more serious problem than full cross-browser compatibility of his product. This is probably one of the main tasks of a good specialist: to ensure that his website is always displayed correctly in all browsers.

The required parameter, which is sometimes used for input, does not work in ancient IE, which simply cannot be left like that. Retired users who are still using IE6 should have the same ease of use with your site as users of the latest version of Google Chrome. Who, besides web developers, can take care of them.

About the sore point, about Internet Explorer

For normal browsers, which include Firefox, Opera and Google Chrome, this task is relatively easy. Even older versions of these browsers display HTML code equally well, unless, of course, some new technologies are used. But to achieve this in browsers of the Internet Explorer family, simply Herculean efforts are required.

Each version of the Internet Explorer browser has its own unique stupidity. What works in IE6 may not work properly in IE7 and vice versa. Microsoft could not overcome this zoo even in the latest version of its browser.

I can’t understand why browser developers can’t just open and read the W3C standards for website building.

Therefore, as a web developer, I have to act as a kind of “layer” between capricious browsers and site visitors who require knowledge and spectacle. And it’s great that web developers have managed to do this so far.

So, how can I get required to work in older versions of IE?

JS comes to our aid. Previously, I couldn’t stand it, but now I don’t see a further path without it in the expanse of the “correct” WEB.

I did not invent the solution given below myself, but took it from a bourgeois blog. Since I am greedy and the blog is bourgeois, I will not provide a link to it.

The fnCheckFields() function will be responsible for everything. Place the JS code on your site:

function fnCheckFields(form_obj)( var error_msg = "Please fill out all required fields."; var is_error = false; for (var i = 0; form_obj_elem = form_obj.elements[i]; i++) if (form_obj_elem.type "input" || form_obj_elem.type "text") if (form_obj_elem.getAttribute("required") && !form_obj_elem.value) is_error = true; if (is_error) alert(error_msg);

Usually it is recommended to place it between the HEAD html tags at the beginning of the page, but I would still recommend placing it at the very bottom of the page before the closing BODY tag. This way JS has less impact on page loading speed.

The input window where the required parameter should be entered should look like this in html:

This script works very simply: after clicking the Submit button, the script checks all inputs for the presence of the required parameter and if it finds it, it looks at the entered value of this field accordingly. If nothing is entered into such an input, a warning window about the need for input is displayed. Accordingly, the data is not sent anywhere.

It’s also great that if you have a normal browser that has already learned to understand this parameter as expected, such a warning window will not pop up and the standard tools for processing the required parameter for your browser will work.

Share on social media networks

0

I'm building a tiny PHP MVC framework and here is my structure

/app /controllers /models /views /templates /config /config.php /core /Controller.php /Router.php /init.php /index.php

folders Inside index.php which is the front controller I have this code to require from init.php /app/core/init.php

app/core/init.php

init.php requires every base controller and Classe in the /core directory, including controller.php and router.php and here index.php also instantiates the classes

Every thing is working fine for now, as I have tested it by creating a constructor in both controller.php and router.php so the code in these two files will be like this

app/core/controller.php

application/kernel/router. php

inside index.php it echoes OK! as the classes are created correctly but the problem is when I want to include config.php which is in /app/config/config.php from Controller.php which is in /app/core/Controller.php with this code

Every time I do this it returns this error

Controller::include(../config/config.php) : failed to open stream: No such file or directory in C:\AppServ\www\myapp\app\core\Controller.php on line 6

Controller::include() : Failed opening "../config/config.php" for inclusion (include_path=".;C:\php5\pear") in C:\AppServ\www\myapp\app\core\Controller .php on line 6

I think I used the correct location, I'm working with /app/core/Controller.php and w ant requires /app/config/config.php. I'm returning to one directory using ../

Then why can't I claim the file?

  • 3 answers
  • Sorting:

    Activity

2

From my personal experience, using relative file paths will lead to headaches at some point. So I usually use the full path to the file. The advantage of this is also that it is slightly faster. Then if at some point you get an include error, it's easier to find the error since you have the entire path available.

To be able to do absolute paths, I would recommend that you add a constant to your index.php (frontcontroller) file. Something like the following:

Define("ROOT_PATH", realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR);

Defines a constant called ROOT_PATH which refers to the directory where the index.php file is located, and therefore your root directory. At the same time, I added a directory separator to the end to make it easier to write paths. To use this, you must write.

Require_once ROOT_PATH . "config/config.php";

Bonus Information

But if you use this approach in your controller.php class you make it depend in this constant. To fix this, you can pass the root path as a variable in the constructor.

Public function __construct($root) (...

And then use it like the following:

Public function __construct($root) ( require_once($root . "config/config.php"); )

Hope this helps.

0

I don't know what's going on, but require_once() was not throwing an error when referring to itself as include() because they are different functions, plus if this is the whole code, the error line number is not the same as your require_once() line, since it should be 4. Try restarting your webserver and see if that fixes anything, otherwise you'll probably be making a joke of something.