HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Inputting data and displaying elsewhere?
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Form
View previous topic :: View next topic  
Author Message
Jurek



Joined: 22 Dec 2004
Posts: 2

PostPosted: Wed Dec 22, 2004 8:07 am     Inputting data and displaying elsewhere? Reply with quote

Hi all, I have recently set up a form on my website. The user inputs information, clicks submit and I get a nice email with the user's information whilst the user is directed to a page thanking them for supplying the information. So far so good.

Now, what I need to know is how easy is it to make the 'thankyou' page that the user is directed to, 'clever'. What I mean is a page which takes the information the user has inputted and displays it as a sort of confirmation page displaying the users name, address, phone number etc.

All my code is straight forward HTML and I use FormMail in my CGI bin courtesy of Matts Script Archive.

Thanks,

Jurek.
kanenas



Joined: 14 Dec 2004
Posts: 191

PostPosted: Tue Jan 04, 2005 2:53 am     Server-side or client side scripting are both options Reply with quote

Displaying form data is relatively easy with custom scripts; the tricky part in this case is doing it within the constraints of your current setup.

I assume you are using a hidden 'redirect' field on the form page so that FormMail will redirect the visitor to a response page. If that is the case, you need to include a query string containing the relevant form data in the 'thankyou' page URL (Mozilla based browsers and IE don't seem to repost form data to a redirected page). You can do this by either editing FormMail.pl to generate the query string (check the documentation of the CGI package) or adding javascript to the form page to dynamically construct the URL, as shown below.

Code:
//Client-side solution; this goes in the form page
//make sure submit handler calls createRedirectURL
//'form' is the form object (not ID)
//'page' is the URL of the 'thankyou' page, sans query string
//'fields' is an object containing the properties of the form object to print
createRedirectURL(form, page, fields) {
  var opts = [];
  if (! fields) {
    fields = {address: '', name: '', phone: ''};
  }
  foreach (i in fields) {
    if (form[i]) {
      opts.push(i + '=' + escape(form[i].value));
    }
  }
  document.getElementsByName('redirect')[0].value=page+ '?' + opts.join('&');
}


As for the 'thankyou' page, you again are presented with the choice of server- and client-side scripting. If you use the GET method to send the form data, you can use Javascript to parse 'document.location.search'.

Code:
<script type='text/javascript'><!--
//the 'splice(1)' strips the leading '?'
var search=document.location.search.slice(1).split('&');
var params={};
for (i=0; i<search.length; ++i) {
  opt = search[i].split('=', 2));
  if (opt.length > 1) {
    params[opt[0]] = unescape(opt[1]);
  } else {
    params[opt[0]]='';
  }
}
//'params' now holds parameters;
//use document.writeln or document.createTextNode & document.body.appendChild to
//add values of named parameters where appropriate
//--></script>


Now for server side scripting. If you find a way of POSTing the form data, I believe this is your only option (is POSTed data accessible through any DOM?).

Code:
#! /usr/bin/perl
use CGI ':standard';
...
print "Thank you, ", param('name'), " for your submission.  We now have the following contact information from you:<br>\nAddress: ", param('address'),"<br>\nPhone: ",param('phone'),"<br>\n";
...


Code:
...
<!--PHP example-->
<?php
function pr_elements($val, $name) {
  echo "%name: $val<br>\n";
}
//this will print all fields, including hidden ones
if ('POST' == $_SERVER['REQUEST_METHOD']) {
  array_walk($_POST, 'pr_elements');
} else {
  array_walk($_GET, 'pr_elements');
}
?>
...
Jurek



Joined: 22 Dec 2004
Posts: 2

PostPosted: Tue Jan 04, 2005 7:37 am     Reply with quote

Brilliant, thankyou for a comprehensive reply.


Jurek.
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Form All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial