473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

changing content via another page (using a form)

What i want to do, is have content on a homepage, which can be edited via a form on a restricted page.

E.G.

I have news on home page, when i go to a restricted page (e.g. mysite.co.uk/admin) i am produced a form which if i type in, then enter, the news on the homepage is changed.

I can do this on a single page, but on a separate page is a bit confusing at the moment:

CGI:
Expand|Select|Wrap|Line Numbers
  1. my $query = new CGI;
  2. my $name = $query->param("name");
  3. my $message = $query->param("message");
  4.  
  5. if ($query->param('action') eq 'insert') {
  6. open (INSERT,">>msg.txt");
  7. print INSERT "$name|$message\n";
  8. close(INSERT);
  9.  
  10.       }
  11.  
  12. open (READ,"msg.txt");
  13. my @loop_data = ();  
  14. while (<READ>) {
  15. chomp $_;
  16. my ($db_name,$db_message) = split(/\|/, $_);
  17. my %row_data;  
  18.  
  19. $row_data{NAME} = $db_name;
  20. $row_data{MESSAGE} = $db_message;
  21.  
  22.  push(@loop_data, \%row_data);
  23. }
  24.  
  25.       close(READ);
  26.  
  27. my $template = HTML::Template->new(filename => 'contactus.tmpl');
  28. $template->param(LOOP => \@loop_data);  template
  29. print "Content-Type: text/html\n\n";
  30. print $template->output;
  31.  
  32.  
TMPL:
[html]<TMPL_LOOP NAME="LOOP">
<strong>Name:</strong> <TMPL_VAR NAME="NAME"> <br />
<strong>Message:</strong> <TMPL_VAR NAME="MESSAGE"> <br /><br />
</TMPL_LOOP>
<form action='contactus.cgi' enctype='multipart/form-data' method='post'>
Name:<br />
<input type="text" name="name" /><br />
Message:<br />
<input type="text" name="message" /><br /><br />
<input type="hidden" name="action" value="insert">
<input type='submit' value='submit' />
</form>[/html]Any help would be greatly appreciated.
Sep 20 '07 #1
8 1930
KevinADC
4,059 Expert 2GB
Whats your question?
Sep 20 '07 #2
I want to know 'how' to do this.

Will the method be much different from the code already produced?
Sep 21 '07 #3
KevinADC
4,059 Expert 2GB
Sorry, I re-read your first post and I still don't know what it is you are asking or want to know how to do.
Sep 21 '07 #4
Ok, it's my fault for not explaining properly but:

(apologies if links aren't allowed)

My home page
www.southeastghosttours.co.uk
has several content 'blocks', one of which being a news section.

Instead of accessing the source code directly to change it then uploading it, i want to add a page, for example:

www.southeastghosttours.co.uk/admin
which will present a form.
anything typed then submitted into this form, will change that block of news.

If it is still confusing, il add a image explanation.
Sep 22 '07 #5
eWish
971 Expert 512MB
Just write a script for display purposes then write a separate script ( called admin.pl or whatever ) that will allow you to write to the msg.txt file. Then place the admin.pl file in a protected directory.
Sep 22 '07 #6
theres 3 parts to the 2 codes above.

The cgi script that does the work.
The form in the TMPL and the loop display above it.

So, would i make a page admin.pl which contains the form?
I type into the form,
keep the CGI seperate which does the work?
Then the cgi script does the work.
keep the <loop> display on the 'home' tmpl document.
And its finaly displayed on the home page

So when i type into the form, it will change the content yes?

if so, how does the home.tmpl document call the data being inputted on the admin page?
Sep 25 '07 #7
I maged to figure out how it worked, so thanks anyway.

Now, I have a 'slightly' different problem.

I have /admin/news.cgi
this has a form which provides the form action.

Basically, when i enter the information, it works, but when i redirect back to the page later, its gone.
How am i supposed to store it there?

The process:

Expand|Select|Wrap|Line Numbers
  1. my $query = new CGI;
  2. my $date = $query->param("date");
  3. my $news = $query->param("news");
  4. my $template = HTML::Template->new(filename => 'home.tmpl');
  5.  
  6. if ($query->param('action') eq 'insert') {
  7. open (INSERT,">/home/news.txt");
  8. print INSERT "$date|$news\n";
  9. close(INSERT);
  10. }
  11.  
  12.  
  13. $template->param( 'date' => $date, 'news' => $news);
  14.  
  15.  
  16. open (READ,"/home/news.txt");
  17.  
  18. my @data = <READ>;
  19.  
  20. close(READ);
  21.  
  22. foreach my $line (@data) {
  23. (my $db_date, my $db_news) = split(/\|/,$line);
  24. print "$db_date, $db_news<br>\n";
  25.  
  26. print "Content-Type: text/html\n\n";
  27.  
  28. print $template->output; 
The tmpl:

Expand|Select|Wrap|Line Numbers
  1. <div id="hcn2">&gt; News - ( <TMPL_VAR NAME="DATE"> ) -
  2. <ul>
  3. <li><TMPL_VAR NAME="NEWS"></li>
  4. </ul>
  5. </div>
Help will be great, thanks. =]
Sep 29 '07 #8
eWish
971 Expert 512MB
Joseph,

I put together a sample script that shows how to do some of the things you have asked in this thread. I have also added some comments for you. I have attached the sample files.

--eWish
Attached Files
File Type: txt my_script_tmpl.txt (777 Bytes, 332 views)
File Type: txt my_script.txt (2.1 KB, 412 views)
Sep 30 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: mvargasp | last post by:
Hi all, I have a web form which contains a frame, (a form containing a menu on the left and a web form containing a datagrid on the right). Also there is a button (right side) which transforms...
14
by: Brandon Hoppe | last post by:
I'm trying to change the src of an ilayer in the parent document from a link inside the ilayer. I'm not able to get it to work. All that happens is Netscape 4 crashes. This is for Netscape 4 only....
31
by: Greg Scharlemann | last post by:
Given some recent success on a simple form validation (mainly due to the kind folks in this forum), I've tried to tackle something a bit more difficult. I'm pulling data down from a database and...
1
by: Paul M. Frazier, Ph.D. | last post by:
I am writing a user information update page and I populate the form on Page_Load with the current values of the user's name, etc. When I change the text in one of the textbox controls (e.g.,...
5
by: Mark Fox | last post by:
Hello, When you add a new web form in VS.NET it automatically adds the following namespaces at the top: using System; using System.Collections; using System.ComponentModel; using...
6
by: Mr. x | last post by:
Hello, I have the following aspx code : <form id = "main_form" runat = "server"> <asp:Table dir = "rtl" runat = "server"> <asp:TableRow> <asp:TableCell id =...
0
by: Ramesh | last post by:
I am using a datalist control in my page and it has a header template. In the header template I have a table control with table rows and table cells. While the page is loading I am trying to change...
3
by: Kevin Gorski | last post by:
This question has been asked before, but there have been no definitive answers that I was able to find. Can the viewstate hidden input field be moved to a less prominent page location? On an...
6
by: tshad | last post by:
Is there a way during Page_Load to change or add an attribute to the Body tag? I want to be able to change the onLoad body attribute to do a focus on one of my text boxes, such as: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.