PHP development...LOGIN

PHP development news release system publishing HTML page

new.jpg


The picture above is the news release page we want to do

A simple <form> form, plus a simple CSS background

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文网</title>
   
    <style>
        body{
            background-color: rgba(128, 128, 128, 0.3);
        }
    </style>
    
</head>
<body>
<form  method="post" action="new_post.php" name="myform">
    <h1>发布新闻系统</h1>
    <p>标题:<input type="text" name="title"/></p>
    <p>内容:<textarea cols=30 rows=5 name="content"></textarea></p>
    <p><button>发布新闻</button></p>
</form>
</body>
</html>

We need to do some verification on our news release page. If the title and news content are not filled in, it is not allowed to be published. We use JS to do the verification.

You need to make a verification in the <form> JS event, the code is as follows

<form method="post" action="new_post.php" onsubmit=" return foo();" name="myform">

Add the following code to the head

<script>
function foo(){
if(myform.title.value==""){
          alert('Please fill in your news title');
                                                                                                                                         ;
Alert ('The content of the news cannot be empty');
myForm.Content.focus ();
Return false;
}
}
& lt;/script & gt


#Now if you submit the news for publication without filling in the title and content, it is not allowed to be published

The complete code of the new.html file is as follows

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文网</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no" />
    <style>
        body{
            background-color: rgba(128, 128, 128, 0.3);
        }
    </style>
    <script>
        function foo(){
            if(myform.title.value==""){
                alert('请填写你的新闻标题');
                myform.title.focus();
                return false;
            }
            if(myform.content.value==""){
                alert('新闻内容不能为空哦');
                myform.content.focus();
                return false;
            }
        }
    </script>
</head>
<body>
<form  method="post" action="new_post.php" onsubmit=" return foo();" name="myform">
    <h1>发布新闻系统</h1>
    <p>标题:<input type="text" name="title"/></p>
    <p>内容:<textarea cols=30 rows=5 name="content"></textarea></p>
    <p><button>发布新闻</button></p>
</form>
</body>
</html>
The next step is to submit the news information we filled in on the page to the new_post.php page for processing


Next Section

<!doctype html> <html> <head> <meta charset="utf-8"> <title>PHP中文网</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no" /> <style> body{ background-color: rgba(128, 128, 128, 0.3); } </style> <script> function foo(){ if(myform.title.value==""){ alert('请填写你的新闻标题'); myform.title.focus(); return false; } if(myform.content.value==""){ alert('新闻内容不能为空哦'); myform.content.focus(); return false; } } </script> </head> <body> <form method="post" action="new_post.php" onsubmit=" return foo();" name="myform"> <h1>发布新闻系统</h1> <p>标题:<input type="text" name="title"/></p> <p>内容:<textarea cols=30 rows=5 name="content"></textarea></p> <p><button>发布新闻</button></p> </form> </body> </html>
submitReset Code
ChapterCourseware