FORUM HOME | WHUK BLOG   
WEB HOSTING UK AFFORDABLE WEBSITE HOSTING SERVICES IN UNITED KINGDOM
PHP LINUX SHARED HOSTING WINDOWS ASP.NET HOSTING PACKAGES
ECOMMERCE HOSTING ASP MSSQL MS ACCESS ODBC FRONTPAGE HOSTING
CPANEL WHM FANTASTICO RESELLER DEDICATED SERVER WEB HOSTING
CHEAP PLESK CPANEL HTML MYSQL BEST UK VPS HOSTING COMPANY
CHEAP RELIABLE UK HOSTING PROVIDER SINCE 2001
MANAGED WEB HOSTING SERVICE
AFFORDABLE WEBSITE HOSTING SERVICES IN UNITED KINGDOM

Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum » Web Hosting and Domains » FAQ's / Tutorials.

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 04-06-08, 02:02 PM
Senior Member
 
Join Date: Jul 2007
Posts: 163
Default have your frontpage forms stopped working - help is at hand

http://www.bignosebird.com/formls1.shtml

The above link will give you a simple form (and how to pass it to an email)

To explain this simply for you:
1) you need to start the form inside the HTML with a
Code:
<FORM>
tag.
2) You will need to do this
Code:
<FORM METHOD="POST" ACTION="http://www.yourdomainnamehere.com/cgi-bin/bnbform.cgi">
<INPUT TYPE="hidden" NAME="to" VALUE="emailaddresstogetdata@yourdomainnamehere.com">
    
<INPUT TYPE="hidden" NAME="subject" VALUE="Feedback From Web Site">
  
<INPUT TYPE="hidden" NAME="required" VALUE="name,submit_by">
    
<INPUT TYPE="hidden" NAME="form_id" VALUE="info request from website">
    
<INPUT TYPE="hidden" NAME="submit_to" VALUE="emailaddresstogetdata@yourdomainnamehere.com">
    
<INPUT TYPE="hidden" NAME="data_order" value="name,company,address1,address2,address3,town,county,country,postcode,telephone,submit_by,questions">
where emailaddresstogetdata@yourdomainnamehere.com is the email address you use for the form.

3) then you need to decide what you want to receive in information
a) for text such as names
Code:
<INPUT TYPE="text" NAME="name" SIZE=20 maxlength="80"  VALUE="">
b) a text box that scrolls....
Code:
<TEXTAREA NAME="questions" ROWS=5 COLS=20>
</TEXTAREA>
c) a checkbox ......
Code:
<input type="checkbox" name="callme" value="yes_please">
d) radio buttons
Code:
 Yes <input type="radio" name="like_it" value="yes">
No<input type="radio" name="like_it" value="no">
e) drop downs
Code:
<select name="my_hair_colour_is">
<option>red
<option>pink
<option>blue
<option>striped
</select>

You will ALWAYS need
Code:
<INPUT TYPE="text" NAME="submit_by" SIZE=20 maxlength="80" VALUE="">
as this is their email address and this is always a required field (so you know where to reply to !)

For whatever name you give a field you must enter it in the data_order script bit above otherwise you wont get it. If it is compulsory you must also add it in required bit above too.

And then finally the buttons:

Code:
<INPUT TYPE="submit" VALUE="Send it to us now">
 
<INPUT TYPE="reset" VALUE="start again">
 
</form>
That is how you create the form

To make it work you must also create a file in NOTEPAD
save it as : bnbform.cgi

(can be found thanks to bignosebird.com who give it away free) I have put it in the following post....


YOU MUST change this line in the script to work:
Code:
# @okaydomains=("http://www.mydomain.com", "http://mydomain.com");
to be your domain

YOu can then upload the form (save the form as the name of your current form) and the bnbform.cgi

You can FTP by opening your control panel to your domain and selecting file manager on the panel



Then move to /public_html

Upload the form where your current form is.

then move to cgi-bin and upload the bnbform.cgi

TO MAKE THIS WORK YOU MUST CHANGE PERMISSIONS on the bnbform.cgi once uploaded.

click where it says perms next to the form you have uploaded and make it 755

You have successfully changes frontpage form into a unix perl form
Reply With Quote

  #2 (permalink)  
Old 04-06-08, 02:04 PM
Senior Member
 
Join Date: Jul 2007
Posts: 163
Default

Code:
#!/usr/bin/perl

use Socket;
################################################################## 
#  (C)1998-9 Bignosebird.com   bnbform v3.0
#  This software is FREEWARE! Do with it as you wish. It is yours   
#  to share and enjoy. Modify it, improve it, and have fun with it! 
#  It is distributed strictly as a learning aid and bignosebird.com 
#  disclaims all warranties- including but not limited to:          
#  fitness for a particular purpose, merchantability, loss of       
#  business, harm to your system, etc... ALWAYS BACK UP YOUR        
#  SYSTEM BEFORE INSTALLING ANY SCRIPT OR PROGRAM FROM ANY          
#  SOURCE!                                                          
#
#  Socket based e-mail for cross platform capability!
#
############## SPECIAL FORM VARIABLES ############################
#required:    comma delimited list of required entry fields
#data_order:  comma delimited list indicating what fields to actually
#             print and in what order.
#outputfile:  the name of the file to save the data in if using a file
#emailfile:   the name of the file to hold only the sender e-mail address
#ok_url:      URL to go to if successful
#not_ok_url   URL to go to if unsuccessful
#submit_to:   email address of person to input receive data by mail
#cc_to:       email address of Cc Recipient
#submit_by:   email address of person completing form
#autorespond: if yes, then send confirmation to submitter
#automessage: text to print for autoconfirmation e-mail
#form_id:     name of form for e-mail subject
#countfile:   name of file for serial number counter
#okaydomains: prevents calling the script from other sites,
#             without restricting e-mail addresses.
#             replaces $SECURE_NAME from earlier versions.
#             use only lower case letters.
#SMTP_SERVER: the full host name of the server providing e-mail
#             gateway service
##################################################################


## MAIN ##########################################################

# uncomment the line below, and change bignosebird to your domain
# name if you wish to make is so the script can only be called
# from your site.
the next bit follows....
Reply With Quote

  #3 (permalink)  
Old 04-06-08, 02:06 PM
Senior Member
 
Join Date: Jul 2007
Posts: 163
Default

Code:
# @okaydomains=("http://www.mydomain.com", "http://mydomain.com");  

#SMTP_SERVER: indicates the name of the host acting as the e-mail
#             gateway. "localhost" should work on most systems.

#$SMTP_SERVER="localhost";

#OR IF SMTP IS UNAVAILABLE TO YOU, USE SEND_MAIL-
# BUT NOT BOTH!

$SEND_MAIL="/usr/sbin/sendmail -t";

$lockfile="/tmp/bnbform.lck";

   &decode_vars;
   &valid_page;
   if ($fields{'countfile'} ne "")
      { &get_number; }
   &valid_data;
   &write_data;

   if ($fields{'autorespond'} eq "yes")
    { &answer_back; }

   if ($fields{'ok_url'} ne "")
    { print "Location: $fields{'ok_url'}\n\n"; exit;}
     else { &thank_you; }

##################################################################
sub write_data
{
   if ($fields{'submit_by'} ne "")
     {
       if (&valid_address == 0)   
        {
          &bad_email;
          exit;
        }
     }
   
   if ($fields{'submit_by'} ne "" && $fields{'emailfile'} ne "")
    {
      open (EMF,">>$fields{'emailfile'}");
      print EMF "$fields{'submit_by'}\n";
      close (EMF);
    }
   $the_date=localtime();
   if ($fields{'submit_to'} ne "")
    {
     $msgtext="";
     $msgtext .= "On $the_date,\n";
     $msgtext .=  "The following information was submitted:\n";
     $msgtext .=  "Host: $ENV{'REMOTE_ADDR'}\n";
    }
   if ($fields{'outputfile'} ne "")
    { 
      &get_the_lock; 
      open(OUT_FILE,">>$fields{'outputfile'}"); 
    }
   foreach $to_print (@sortlist)
    {
      if ($fields{'outputfile'} ne "")
       { print OUT_FILE "$fields{$to_print}\|"; }
      if ($fields{'submit_to'} ne "")
       { $msgtext .= "$to_print = $fields{$to_print}\n"; }
    }
   if ($fields{'outputfile'} ne "")
    {
     print OUT_FILE "$the_date\|\n";
     close(OUT_FILE);
     &drop_the_lock;
    }
   if ($fields{'submit_to'} ne "")
    {
      $mailresult=&sendmail($fields{submit_by}, $fields{submit_by}, $fields{submit_to}, $SMTP_SERVER, $fields{form_id}, $msgtext);
      if ($mailresult ne "1")
      {print "Content-type: text/html\n\n";
       print "MAIL NOT SENT. SMTP ERROR: $mailcodes{'$mailresult'}\n";
       exit
      }
    }
   if ($fields{'cc_to'} ne "")
    {
      $mailresult=&sendmail($fields{submit_by}, $fields{submit_by}, $fields{cc_to}, $SMTP_SERVER, $fields{form_id}, $msgtext);
    }
}

##################################################################
sub decode_vars
 {
  $i=0;
  read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
  @pairs=split(/&/,$temp);
  foreach $item(@pairs)
   {
    ($key,$content)=split(/=/,$item,2);
    $content=~tr/+/ /;
    $content=~s/%(..)/pack("c",hex($1))/ge;
    $content=~s/\t/ /g;
    $fields{$key}=$content;
    if ($key eq "data_order")
      {
       $content=~s/ //g;
       @sortlist=split(/,/,$content);
      }
    if ($key eq "required")
      {
       $content=~s/ //g;
       @mandatory=split(/,/,$content);
      }
   }
}

##################################################################
sub valid_data
  {
   if ($fields{'data_order'} eq "")    #make sure we have work to do!
    {
      print "Content-type: text/html\n\n"; 
      print <<__W1__;

      <H1>NO data_order list SPECIFIED!</H1>

__W1__
      exit;
    }

   foreach $to_check (@mandatory) #test all required fields, bail on 1st bad
    {                             
      if ($fields{$to_check} eq "")
        {
          if ($fields{'not_ok_url'} ne "")
            { 
              print "Location: $fields{'not_ok_url'}\n\n";
              exit;
            }
             else
              {
                &try_again;
              }
         }
    }

  }

##################################################################
sub thank_you
  {
      print "Content-type: text/html\n\n"; 
      print <<__W2__;

      <H1>Thank you!</H1>
      Your information has been sent and we will be in contact 
      with you soon.<br><br><b>TBC Ltd</b>

__W2__
      exit;
  }

##################################################################
sub try_again
  {
      print "Content-type: text/html\n\n"; 
      print <<__W3__;

      <H1>Missing Data!</H1>
      <B>Please press the back button and fill in
      all required fields!<P></B>

__W3__
      exit;
  }

##################################################################
sub answer_back
 {

   $subject = "Thank you";
   $msgtext="";
  if ($fields{'automessage'} ne "")
   {
    open (AM,"< $fields{'automessage'}");
    while (<AM>)
     {
      chop $_;
      $msgtext .= "$_\n";
     } 
    close(AM);
   }
    else
    {
      $msgtext =<<__W4__;

Thank you for your submission. I will be
getting in touch with you soon.

__W4__
    }
      $mailresult=&sendmail($fields{submit_to}, $fields{submit_to}, $fields{submit_by}, $SMTP_SERVER, $subject, $msgtext);
 }

##################################################################

sub get_number
 {
   $newnum=0;
   open(COUNTER,"<$fields{'countfile'}");
   while(<COUNTER>)
     {
      $newnum = $_ + 1;
     }
   close(COUNTER);
   open(COUNTER,">$fields{'countfile'}");
   print COUNTER "$newnum";
   close (COUNTER);
   $fields{'counter'}=$newnum
 }

##################################################################
sub valid_address 
 {
  $testmail = $fields{'submit_by'};
  if ($testmail =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
  $testmail !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
   { return 0; }
   else { return 1; }
}

##################################################################
sub bad_email
{
print <<__STOP_OF_BADMAIL__;
Content-type: text/html

<FONT SIZE="+1">
<B>
SORRY! Your request could not be processed because of an
improperly formatted e-mail address. Please use your browser's 
back button to return to the form entry page.
</B>
</FONT>
__STOP_OF_BADMAIL__
}

sub get_the_lock
{
  local ($endtime);                                   
  $endtime = 60;                                      
  $endtime = time + $endtime;                         
  while (-e $lockfile && time < $endtime) 
   {
    # Do Nothing                                    
   }                                                   
   open(LOCK_FILE, ">$lockfile");                     
}

sub drop_the_lock
{
  close($lockfile);
  unlink($lockfile);
}


##################################################################
sub valid_page
 {
  if (@okaydomains == 0)
     {return;}
  $DOMAIN_OK=0;                                         
  $RF=$ENV{'HTTP_REFERER'};                             
  $RF=~tr/A-Z/a-z/;                                     
  foreach $ts (@okaydomains)                            
   {                                                    
     if ($RF =~ /$ts/)                                  
      { $DOMAIN_OK=1; }
   }
   if ( $DOMAIN_OK == 0)                                
     {print "Content-type: text/html\n\n Sorry....Cant run from here!";    
      exit;
     }
 }
Reply With Quote

  #4 (permalink)  
Old 04-06-08, 02:07 PM
Senior Member
 
Join Date: Jul 2007
Posts: 163
Default

and finally the last bit
Code:
###################################################################
#Sendmail.pm routine below by Milivoj Ivkovic 
###################################################################
sub sendmail  {

# error codes below for those who bother to check result codes <gr>

# 1 success
# -1 $smtphost unknown
# -2 socket() failed
# -3 connect() failed
# -4 service not available
# -5 unspecified communication error
# -6 local user $to unknown on host $smtp
# -7 transmission of message failed
# -8 argument $to empty
#
#  Sample call:
#
# &sendmail($from, $reply, $to, $smtp, $subject, $message );
#
#  Note that there are several commands for cleaning up possible bad inputs - if you
#  are hard coding things from a library file, so of those are unnecesssary
#

    my ($fromaddr, $replyaddr, $to, $smtp, $subject, $message) = @_;

    $to =~ s/[ \t]+/, /g; # pack spaces and add comma
    $fromaddr =~ s/.*<([^\s]*?)>/$1/; # get from email address
    $replyaddr =~ s/.*<([^\s]*?)>/$1/; # get reply email address
    $replyaddr =~ s/^([^\s]+).*/$1/; # use first address
    $message =~ s/^\./\.\./gm; # handle . as first character
    $message =~ s/\r\n/\n/g; # handle line ending
    $message =~ s/\n/\r\n/g;
    $smtp =~ s/^\s+//g; # remove spaces around $smtp
    $smtp =~ s/\s+$//g;

    if (!$to)
    {
	return(-8);
    }

 if ($SMTP_SERVER ne "")
  {
    my($proto) = (getprotobyname('tcp'))[2];
    my($port) = (getservbyname('smtp', 'tcp'))[2];

    my($smtpaddr) = ($smtp =~
		     /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
	? pack('C4',$1,$2,$3,$4)
	    : (gethostbyname($smtp))[4];

    if (!defined($smtpaddr))
    {
	return(-1);
    }

    if (!socket(MAIL, AF_INET, SOCK_STREAM, $proto))
    {
	return(-2);
    }

    if (!connect(MAIL, pack('Sna4x8', AF_INET, $port, $smtpaddr)))
    {
	return(-3);
    }

    my($oldfh) = select(MAIL);
    $| = 1;
    select($oldfh);

    $_ = <MAIL>;
    if (/^[45]/)
    {
	close(MAIL);
	return(-4);
    }

    print MAIL "helo $SMTP_SERVER\r\n";
    $_ = <MAIL>;
    if (/^[45]/)
    {
	close(MAIL);
	return(-5);
    }

    print MAIL "mail from: <$fromaddr>\r\n";
    $_ = <MAIL>;
    if (/^[45]/)
    {
	close(MAIL);
	return(-5);
    }

    foreach (split(/, /, $to))
    {
	print MAIL "rcpt to: <$_>\r\n";
	$_ = <MAIL>;
	if (/^[45]/)
	{
	    close(MAIL);
	    return(-6);
	}
    }

    print MAIL "data\r\n";
    $_ = <MAIL>;
    if (/^[45]/)
    {
	close MAIL;
	return(-5);
    }

   }

  if ($SEND_MAIL ne "")
   {
     open (MAIL,"| $SEND_MAIL");
   }

    print MAIL "To: $to\n";
    print MAIL "From: $fromaddr\n";
    print MAIL "Reply-to: $replyaddr\n" if $replyaddr;
    print MAIL "X-Mailer: Perl Powered Socket Mailer\n";
    print MAIL "Subject: $subject\n\n";
    print MAIL "$message";
    print MAIL "\n.\n";

 if ($SMTP_SERVER ne "")
  {
    $_ = <MAIL>;
    if (/^[45]/)
    {
	close(MAIL);
	return(-7);
    }

    print MAIL "quit\r\n";
    $_ = <MAIL>;
  }

    close(MAIL);
    return(1);
}
Reply With Quote

  #5 (permalink)  
Old 05-06-08, 09:46 AM
black-dog's Avatar
Senior Member
 
Join Date: May 2008
Location: Newcastle under Lyme
Posts: 205
Send a message via Yahoo to black-dog
Default

Quote:
Originally Posted by byteme View Post
where emailaddresstogetdata@yourdomainnamehere.com is the email address you use for the form.
I really don't like email addresses encoded in webpages. Far better to have them hidden in the script.

For a somewhat simpler method may I suggest my humble offering?
Works with any bog standard web form.
Reply With Quote

  #6 (permalink)  
Old 05-06-08, 11:05 AM
Senior Member
 
Join Date: Jul 2007
Posts: 163
Default

if you want to do this with the form you have you can delete the submit_to and to fields in the form and go the the bnbform.cgi

Code:
 @okaydomains=("http://www.mydomain.com", "http://mydomain.com");
after this line type:
Code:
$submit_to="youremail@mydomain.com" ; 
$to="youremail@mydomain.com" ;
then no email address is shown in the form
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT. The time now is 12:43 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Copyright 2001-2010 Web Hosting UK. All rights reserved.
Web Hosting UK Forum





Site Map

Shared Cloud
Shared Cloud From £1

Affiliate Program
Earn up to £300 Per Sale

Dedicated Servers
Dedicated Server Hosting

Cloud Hosting
Cloud Server Hosting

Load Balanced Server
Load Balancing Server

VPS Hosting
Linux VPS Hosting

Windows VPS
Windows 2003 VPS

Zimbra Hosting
Zimbra Email Hosting

cPanel Hosting
Shared Linux Hosting

Windows Hosting
Shared Windows Hosting

Coldfusion Hosting
Windows Coldfusion Hosting

cPanel Reseller Hosting
Reseller Hosting

Windows Reseller
Windows Reseller Hosting

Email Web Hosting
Email Hosting

Semi-Dedicated Server
Semi-Dedicated Hosting

Remote Backup Plans
Offsite Backup Service


cpanel hosting
Knowledgebase Articles

Pre-Sales Question
Web Hosting FAQ's

Dedicated Hosting
Dedicated Server FAQ's

Virtual Private Servers
VPS Hosting

PHP MySQL Hosting
cPanel Hosting

Windows Hosting
ASP MSSQL Hosting

Domain Name
Domain registration FAQ's

CMS Hosting
CMS Hosting FAQ's

Payment Gateways
Payment FAQ's


Support Tutorials

cPanel Tutorials
cPanel Flash Tutorials

Wordpress Tutorials
Wordpress Flash Tutorials

Plesk Tutorials
Plesk Flash Tutorials

PhpMyadmin Tutorials
PhpMyadmin Flash Tutorials

Drupal Tutorials
Drupal Flash Tutorials

Mambo Tutorials
Mambo Flash Tutorials

Joomla Tutorials
Joomla Flash Tutorials

More Hosting Tutorials