www.webdeveloper.com
Results 1 to 6 of 6

Thread: Using javascript form to post message on home page

  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Using javascript form to post message on home page

    Have a client that wants to be able to post quick messages on their home page. Is there a way to set up a js form on a page that will post a message in a text box on their home page. An example of this is "Dojo closed due to weather".

    I can secure the page with the message form that the client would type their message in...

  2. #2
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,105
    The problem with using JavaScript alone for this is that you need to be able to store the data somewhere. JavaScript cannot be used to write data to a server ... whether it's a file or database.
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  3. #3
    Join Date
    Jun 2012
    Posts
    3
    OK, so what is the simplest solution. It seems that a content management system like dropal is overkill for this...

  4. #4
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,105
    You have a MySQL database and PHP?
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  5. #5
    Join Date
    Jun 2012
    Posts
    3
    I can load a SQL database on the server. Not a strong PHP programmer, but can find one...

  6. #6
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,105
    Easiest way may just be to write the message to a file, then include that file where you want the message to be displayed.

    Here's a basic PHP solution.

    home.php
    Code:
    <!doctype html>
    
    <html lang="en">
    	<head>
    		<meta charset="utf-8" />
    		<title>Title</title>	
    	</head>
    	<body>
    		<header>
    			<h1>Message of the day</h1>
    			<p><?php include('message.php'); ?></p>
    		</header>	
    	</body>
    </html>
    admin.php
    Code:
    <!doctype html>
    
    <html lang="en">
    	<head>
    		<meta charset="utf-8" />
    		<title>Title</title>	
    	</head>
    	<body>
    		<header>
    			<h1>Update the message</h1>
    		</header>	
    	</body>
    </html>
    
    <form method="post" action="change-message.php">
    	<textarea name="message"></textarea>
    	<input type="submit" value="Update the message" />
    </form>
    change-message.php
    Code:
    <?php
    	$fp = fopen('message.php', 'w');
    	fwrite($fp, $_POST['message']);
    	fclose($fp);
    ?>
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles