Jump to content

Php Form


boxturt

Recommended Posts

I am starting very small here and the answer may be very simple. So much so that I am just not seeing it. Then again..... :unsure:

 

Basic Form

<html>

<head><title>oneword.html</title></head>

<body>

<form action="oneword.php" method="post">

Enter the Title : <input type="text" name="title" size=50>

Enter the Author: <input type="text" name="author" size=50>

<input type="submit" value="Pass The Form">

</form>

</body>

</html>

So far so good. This does indeed pass the info to the next page, oneword.php :
<html>

<head><title>oneword.php</title></head>

<body>

<form action="/cgi-bin/submission/xxxxxx.cgi" method="POST">

<textarea name="lyrics" cols=75 rows=30>

 

<?php

$title  = $_POST['title'];

$author = $_POST['author'];

echo "The title is , $title\n";

echo "The author is , $author";

?>

 

</textarea>

<br>

<input type=submit value="SUBMIT">

</form>

</body>

</html>

 

The output is perfect on the site page.

The title is , THIS IS A TITLE

The author is , He Wrote It

The email however is not :
lyrics:  <br>

The title is , THIS IS A TITLE<br>

The author is , He Wrote It<br>

 

It's the <br> I can't figure out how to get rid of. I certainly don't expect anyone to spend any time on this but if ya see something.......

 

Geez, how hard can it be...?? :(

 

now THAT was a dumb question.....

Link to comment
Share on other sites

hm...so you email this...

 

what does this script do. /cgi-bin/submission/xxxxxx.cgi

 

not sure why you use \n in your echo if that just a linebreak for php...doesn't really do anything to the html output...You should be using a "<br />". NOt sure what you mean about when you email.... you may need to set the email to html...or you could just strip the breaks...not sure..need to know more.

Link to comment
Share on other sites

Ty, section31 is correct. We need to see what's going on in the cgi script being called from oneword.php

 

And section31, I love the Family Guy avatars your using! :dance:

You are like the 10th person to compliment me on my avatar... Thanks...hehe

Link to comment
Share on other sites

Those avatars are excellent!!

 

Line won't break without the \n when it is displayed in the textarea in oneword.php unless I do this:

<?php

$title  = $_POST['title'];

echo "The title is , $title";

?>

 

<?php

$author = $_POST['author'];

echo "The author is , $author";

?>

But the emailed output is the same. I feel bad posting the entire code but here it is. Certain things relevant only to me are disguised.

#!/usr/bin/perl

## make sure the path to pearl is correct above. ##

 

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

####

##  FILE: novice.cgi                                                                    ##

##                                                                                      ##

##  Novice Forms                                  Version 1.1                          ##

##  © Copyright 2000-2003 Seth Michael Knorr      mail@sethknorr.com                    ##

##                                                                                      ##

##                      http://www.noviceforms.com/                                    ##

##        Please contact me with any bugs found, or any bug fixes.                    ##

##                                                                                      ##

##        This script is a spin off of the original ©Biz Mail Form                    ##

##                                                                                      ##

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

####

##                                                                                      ##

##  There is no email support provided for this script, the only support can be        ##

##  found at our web site: http://www.noviceforms.com/                                  ##

##                                                                                      ##

##                                                                                      ##

##  ANY PERSON(S) MAY USE AND MODIFY THESE SCRIPT(S) FREE OF CHARGE FOR EITHER BUSINESS ##

##  OR PERSONAL, HOWEVER AT ALL TIMES HEADERS AND COPYRIGHT MUST ALWAYS REMAIN IN TACT. ##

##                                                                                      ##

##  REDISTRIBUTION FOR PROFIT IS PROHIBITED WITH OUT THE CONSENT OF SETH KNORR.        ##

##                                                                                      ##

##  By using this code you agree to indemnify Seth M. Knorr from any liability that    ##

##  might arise from its use.                                                          ##

##                                                                                      ##

##                                                                                      ##

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

####

 

 

## $sendto and $ccto is Where form submissions will be sent,        ##

## (REMEMBER THE \ BEFORE THE @ SIGN example: \@)                    ##

## $sendto = "sendto\@******";  CORRECT WAY!!!!              ##

## $sendto = "sendto@******";  WILL NOT WORK!!!!            ##

 

 

$sendto = "ty\@xxxxx.net";  ## (REMEMBER THE \ BEFORE THE @ SIGN)##

 

##$ccto = "cc\@******";##        ## (REMEMBER THE \ BEFORE THE @ SIGN)##

 

 

 

## $useLib defines the method of sending the email form info to you.                    ##     

## Set $useLib = "sendmail"; TO USE THE SENDMAIL METHOD                                ##

## Set $useLib = "smtp"; TO USE THE SMTP METHOD                                        ##

 

        $useLib = "sendmail";

 

        $mailprog = "/usr/sbin/sendmail"; ## $mailprog  Is the path to sendmail on your server  ##

 

        ##$smtp = "smtp.host.com";##  ## Optional $smtp is your smtp server address    ##

                                    ## example: smtp.host.com                        ##

                                    ## You only configure this is not using sendmail ##

 

 

## to use @okurls to verify the url the form is submited by; set $setokurl to 1 and      ##

## set $setokurl to 0 if you do not want to use @okurls to verfiy form submission URL    ##

 

        $setokurl = "1";

 

        @okurls = ("http://www.xxxxxxxx.com", "http://xxxxxxx.com", "xxx.xx.xxx.xx");

 

 

 

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

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

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

#############  N O  N E E D  T O  E D I T  A N Y  V A R I A B L E S  B E L O W  #############

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

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

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

 

 

    my($offset) = @_;

    $offset = $offset * 86400;

 

    my($sec, $min, $hour, $dayofmonth, $mon, $year, $weekday, $dayofyear, $IsDST) = localtime(time + $offset);

    $year = $year + 1900;

    my(@months) = ("JA", "FB", "MR", "AP", "MY", "JN", "JL", "AG", "SP", "Oc", "NV", "DE");

    my($monthname) = $months[$mon];

    my(@monthsnum) = ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");

    my($monthnamenum) = $monthsnum[$mon];

 

    my(@monthsactual) = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

    my($monthnameactual) = $monthsactual[$mon];

 

 

    my(@days) = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");

    my($dayname) = $days[$weekday-1];

 

${'monthname'} = "$monthname";

${'monthnamenum'} = "$monthnamenum";

${'dayofmonth'} = "$dayofmonth";

 

${'hour'} = "$hour";

 

if ($hour <= 13){

$hour = "$hourplus";

$newhour = ($hourplus-12);

 

}else{

$newhour = "$hour";

}

 

 

if ($min <= 9){

$newmin = "0$min";

}else{

$newmin = "$min";

}

 

 

$footer = "<br><br><br><br><br><center><font face='Arial'><a href='http://www.noviceforms.com/' target='_blank'><font color='#ff0000'>Form processing script provided by Novice Forms</font></a> </center></font>";

 

$backbutton = "<br><br><b>Hit your browsers back button and resubmit the form.</b>";

 

if($ENV{'REQUEST_METHOD'} eq "GET") {

&nopost;

}else{

&get_form_data;

&main;

}

 

sub nopost {

 

print "Content-type: text/html\n\n";

 

print <<"MYMAINtext";

 

<html>

 

<head>

<title>Novice Forms          Version 1.1 </title>

</head><body bgcolor="#cfcfcf">

<center>

 

 

<table width=500 border=1><tr><td bgcolor="#000080">

<br><br>

<font face="Arial" color="#ffffff">

<center>

Novice Forms                Version 1.1<br><br>

 

© Copyright 2000-2003 Seth Knorr<br><br>

A free download of this script can be found at: <a href="http://www.noviceforms.com/" target="_blank"> <font color="#ff0000"><b> http://www.noviceforms.com/ </b></font></a>

</font></center>

<br><br>

</td></tr></table>

</center>

 

</body></html>

 

MYMAINtext

 

exit;

 

}

 

 

sub get_form_data {

 

 

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs=split(/&/,$buffer);

foreach $pair (@pairs)

{

  @a = split(/=/,$pair);

  $name=$a[0];

  $value=$a[1];

  $value2=$a[1],;

  $name =~ s/\+/ /g;

  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

  $value =~ s/~!/ ~!/g;

  $value =~ s/\+/ /g;

  $value =~ s/(\r)+/\-\-/g;

  $value =~ s/\n+//g;

  $value =~ s/(\-\-)+/\n/g;

                $value =~ s|\&|\&amp\;|g;

                $value =~ s|<|\&lt\;|g;

                $value =~ s|>|\&gt\;|g;

                $value =~ s|\n|<br>\n|g;

 

  push (@POST,$name);

  push (@POST,$value);

  push (@formname,$name);

  push (@formvalue,$value);

 

}

%POST=@POST;

%POST;

%formname=@formname;

%formname;

%formvalue=@formvalue;

%formvalue;

 

 

}

 

 

sub main {

 

    @sortfields = split(/,/,$POST{'sort'});

 

    @required = split(/,/,$POST{'required'});

 

for ($indexreq = 0; $indexreq < @required; $indexreq++) {

$myrequired = $required[$indexreq];

$myformreq = $POST{"$myrequired"};

 

 

  if ($myrequired eq "email"){

      if (!$myformreq || $myformreq =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $myformreq !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)$/){

      &missing_email;

      }

  }

  elsif (!$myformreq){

  &format_error;

  }

 

}

 

 

## START $setokurl  ##

 

                    if ($setokurl =~ /1/){

 

  $url = "0";

  $referer = "$ENV{'HTTP_REFERER'}";

 

 

  foreach $myokurls (@okurls) {

    if ($referer =~ /$myokurls/) {

      $url = "1";

      }

 

  }

  if ( $url == 0) {

 

  &bad_okurl;

  }

 

                    }

 

 

## END $setokurl  ##

 

 

        &notify;

 

 

        if (! $POST{'success_page'}){

        &success;

        }else{

        print "Location: $POST{'success_page'}\n\n";

        }

 

 

 

}  ## END "SUB MAIN" ##

 

sub success {

 

 

print "Content-type: text/html\n\n";

 

print <<"Myformatsuccess";

 

<html>

<head>

<title>Thank You.</title>

</head>

<body>

<BR><BR><CENTER>

<h2>Your form has been submitted successfully!</h2>

 

 

</CENTER>

 

 

$footer

 

</body>

</html>

 

Myformatsuccess

 

 

exit;

 

}

 

 

sub missing_email {

 

$title = "<title>Missing or invalid format of email!</title>";

$errormessage = "<h2>Missing or invalid format of email.</h2><b>The email Field must be filled in and in the proper format!</b>";

 

print "Content-type: text/html\n\n";

 

print <<"missingemailERROR";

 

$title

 

$errormessage

 

$backbutton

 

$footer

 

missingemailERROR

 

exit;

 

}

 

 

sub bad_okurl {

 

$title = "<title>Invalid Reffering URL.</title>";

$errormessage = "<h2>Invalid Referring URL.</h2><b>If you are the administrator, edit the \@okurls in the novice.cgi script or turn this feature off.</b>";

 

 

print "Content-type: text/html\n\n";

 

print <<"badurlERROR";

 

$title

$errormessage

$footer

 

badurlERROR

 

exit;

 

}

 

 

 

sub format_error {

 

 

for ($indexreq = 0; $indexreq < @required; $indexreq++) {

$myrequired = $required[$indexreq];

$myformreq = $POST{"$myrequired"};

 

if (!$myformreq){

 

$REQUIRED{"$indexreq"} = "${'LISTITEMS'}<li> $myrequired";

${'LISTITEMS'} = $REQUIRED{"$indexreq"};

 

}

}

 

 

$title = "<title>Missing form fields!</title>";

$errormessage = "<h2>Missing form fields!</h2><b>The Below Required Fields Where Left Blank:</b><br><br>${'LISTITEMS'}<br><br><b>Hit your browsers back button and resubmit the form.</b>";

 

print "Content-type: text/html\n\n";

 

print <<"MyformatERROR";

 

$title

$errormessage

$backbutton

$footer

 

MyformatERROR

 

exit;

 

}

 

 

sub notify{

 

 

if ($useLib eq "sendmail") {

 

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

#      ABOVE CHECKS WHAT SEND TYPE TO USE  #

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

 

$msgSubject = "Novice Form Submission" . "$POST{'subject'}";

 

  open(MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";

print MAIL "To: $sendto\n";

        if ($ccto){

        print MAIL "Cc: $ccto\n";

        }

print MAIL "From: $POST{'email'}\n";

print MAIL "Subject: $msgSubject\n";

print MAIL "The form below was submited by $POST{'email'} form Ip address: $ENV{'REMOTE_ADDR'} on $monthnameactual $dayofmonth, $year at $newhour:$newmin\n";

print MAIL "-------------------------------------------------------------------------\n\n";

 

 

if (! $POST{'sort'}) {

 

 

  for ($indexval = 0; $indexval < @formvalue; $indexval++) {

  ${'myname'} = $formname[$indexval];

  ${'myvalue'} = $formvalue[$indexval];

 

 

if (${'myname'} eq "subject" || ${'myname'} eq "required" || ${'myname'} eq "sort" || ${'myname'} eq "success_page" || ${'myname'} eq "ccto" || ${'myname'} eq "sendto"){

$dontrun = "1";

}else{

$dontrun = "";

}

 

if (! $dontrun){

print MAIL "${'myname'}:  ${'myvalue'} \n\n";

}

  }

 

}else{  ##ELSE IF NO SORT FIELD ##

 

for ($numsort = 0; $numsort < @sortfields; $numsort++) {

$sfield = $sortfields[$numsort];

${'sfieldvalue'} = $POST{"$sfield"};

${'sfield'} = "$sfield";

 

print MAIL "${'sfield'}:  ${'sfieldvalue'} \n\n";

 

}

 

} ## END ELSE IF SORT FIELD ##

 

close MAIL;

 

 

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

    }else{  #  END IF SENDMAIL      #

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

 

 

$msgSubject = "Novice Forms Submission" . "$POST{'subject'}";

 

  $nl = "\n";

  $msgMessage = "";

 

$msgMessage=$msgMessage.$POST{'message'}.$nl.$nl.$nl;

$msgMessage=$msgMessage."The form below was submitted by ";

$msgMessage=$msgMessage.$POST{'email'}."    Ip address:  ".$ENV{'REMOTE_ADDR'};

$msgMessage=$msgMessage."  ".$monthnameactual." ".$dayofmonth.", ".$year;

$msgMessage=$msgMessage." at ".$hour.":".$min.$nl;

$msgMessage=$msgMessage."-------------------------------------------------------------------------".$nl.$nl;

 

 

if (! $POST{'sort'}) {

 

for ($indexval = 0; $indexval < @formvalue; $indexval++) {

  ${'myname'} = $formname[$indexval];

  ${'myvalue'} = $formvalue[$indexval];

                if (${'myname'} eq "subject" || ${'myname'} eq "required" || ${'myname'} eq "sort" || ${'myname'} eq "success_page" || ${'myname'} eq "ccto" || ${'myname'} eq "sendto"){

  $dontrun = "1";

  }else{

  $dontrun = "";

  }

  if (! $dontrun) {

  $msgMessage= $msgMessage.${'myname'}.": ".${'myvalue'}.$nl;

  }

}

 

}else{  ##ELSE IF NO SORT FIELD ##

 

for ($numsort = 0; $numsort < @sortfields; $numsort++) {

$sfield = $sortfields[$numsort];

${'sfieldvalue'} = $POST{"$sfield"};

${'sfield'} = "$sfield";

 

$msgMessage .= "${'sfield'}:  ${'sfieldvalue'} \n\n";

 

}

 

} ## END ELSE IF SORT FIELD ##

 

 

 

$msgformat = "text/plain";

 

eval { require(Net::SMTP)};

if ($@) {

print "Failed to load";

exit;

}

 

## send email results##

$smtp = Net::SMTP->new($smtp); # connect to an SMTP server #

$smtp->mail($formdata{'email'}); # use the sender's address here #

$smtp->to ($sendto); # recipient's address #

$smtp->data(); # Start the mail #

 

$smtp->datasend("To: ".$sendto."\n");

$smtp->datasend("From: $formdata{'email'}\n");

$smtp->datasend("Subject: $msgSubject\n");

$smtp->datasend("Content-Type: ".$msgformat);

$smtp->datasend("\n\n");

$smtp->datasend($msgMessage."\n");

$smtp->datasend("\n");

$smtp->datasend("\n");

$smtp->datasend("\n");

$smtp->datasend("\n");

 

$smtp->dataend(); # Finish sending the mail #

$smtp->quit; # Close the SMTP connection #

 

 

 

 

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

    }      #  END IF SMTP  ELSE    #

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

 

 

} ## END &notify;

I'm in waaaaaaay over my head, I can tell :dance:

 

This is actually related to This Post if that helps.

 

Thank You. :goof:

Link to comment
Share on other sites

Those avatars are excellent!!

 

Line won't break without the \n when it is displayed in the textarea in oneword.php unless I do this:

<?php

$title  = $_POST['title'];

echo "The title is , $title";

?>

 

<?php

$author = $_POST['author'];

echo "The author is , $author";

?>

Ty, I think you are embedding the break into your fields. Thus you are getting them in your email.

 

Have you tried changing the php echo line to something like this?

 

echo "The title is , $title \n";

 

Thus, the php would insert the break and you can leave it off the field.

Link to comment
Share on other sites

Yea, thanks. That was the first way I had it set up and that didn't work either.

 

I am now experimenting with a different script ;)

 

Which has its own whole, new set of issues. I just need something to send the form. Basic. Bare. Void of all features. B)

 

I figured it out!! Yay me....lol

Edited by boxturt
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...