Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: adding a fill in form on the site  (Read 6681 times)

0 Members and 1 Guest are viewing this topic.

stock

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 109
adding a fill in form on the site
« on: September 24, 2005, 02:29:29 am »

Hello, can anyone please help.

I am putting together a contact us page to modify my site and within this a fill in form for the viewer to send and email.

I have worked out some coding which looks okay apart from design tweaks but doesn't have the functionality. The code is below and I would be very grateful if someone could tell me what has gone wrong. When you fill in the form, no messages are generated and this doesn't seem to send the email at all. I have clearly missed something but would be grateful for help.

Stock


code from here:


<?php
define('IN_COPPERMINE', true);
require('include/init.inc.php');
pageheader('About Stockshoots');
// your actual page content starts here

    starttable("100%", 'Content block title', 1);
    ?>
   <tr>
    <td class="tableb" valign="top" align="center">
    Hello World
    </td>
    </tr>
   
    <?php
    endtable();
   

if($submit) { // if the form was sent do the following

if($name && $subject && $email && $message ) { // if all fields were filled-in send email
mail("admin@stockshoots.co.uk","$subject","$message","From: $name <$email>") or die("email error");
echo "Message Sent"; // if all went well, display message was sent
} else {
echo "All fields must be filled in!<BR>"; // if not all were filled in, display error message
}
} // end php submission code
?>


<form action="" method="post">
Name: <br>
<input type="text" name="name">
<br>
Email: <br>
<input type="text" name="email">
<br>
Subject: <br>
<input type="text" name="subject">
<br>
Text:<br>
<textarea name="message" cols="60" rows="6"></textarea><br>
<input type="submit" name="submit" value="Send">
<input type="reset" name="Reset" value="Reset">
</form>

<?php                  
                  
// your actual page content ends here





pagefooter();
ob_end_flush();
?>
« Last Edit: September 24, 2005, 08:07:47 am by TranzNDance »
Logged

OmegaGOD

  • Supporter
  • Coppermine frequent poster
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 346
  • I approve.
Re: adding a fill in form on the site
« Reply #1 on: September 24, 2005, 05:20:36 am »

This question really seems like a site customization question and really isn't related to CPG.

Have you tried to search google for adding in an e-mail form?
Logged
Please do not PM me with support questions. Please read the manual and then if posting questions please place them in the proper sub-boards.

stock

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 109
Re: adding a fill in form on the site
« Reply #2 on: September 24, 2005, 05:26:48 am »

hi,

yes, I have changed it to more php code but this doesn't work properly. I would be very grateful if you could have a look. Thanks very very much. The code is below:



<?php
define('IN_COPPERMINE', true);
require('include/init.inc.php');
pageheader('About Stockshoots');
// your actual page content starts here

    starttable("100%", 'Content block title', 1);
    ?>
   <tr>
    <td class="tableb" valign="top" align="center">
    Hello World
    </td>
    </tr>
   
    <?php
    endtable();
    ?>
   
<br>
 
 <?php
   if ($_SERVER['REQUEST_METHOD'] != 'GET'){
      $me = $_SERVER['PHP_SELF'];
   ?>
   <form name="form1" method="POST"
   action="<?php echo $me;?>">
   <table border="0" cellspacing="0" cellpadding="2">
         <tr>
            <td>Name:</td>
            <td><input type="text" name="Name" cols="60" rows="6"></td>
         </tr>
         <tr>
            <td>Email address:</td>
            <td><input type="text" name="Email" cols="60" rows="6"></td>
         </tr>
         <tr><td>Subject</td>
            <td><input type="text" name="Subject" cols="60" rows="6"></td>
         </tr>
         <tr>
            <td valign="top">Message:</td>
            <td><textarea name="MsgBody" cols="60" rows="6"></textarea></td>
         </tr>
         <tr>
            <td>&nbsp;</td>
            <td><input type="submit" name="Submit"
               value="Send"></td>
         </tr>
      </table>
   </form>
   <?php
 }else{
   error_reporting(0);
      $recipient = 'admin@stockshoots.co.uk';
      $subject = stripslashes($_POST['Subject']);
      $from = stripslashes($_POST['Name']);
      $email = ($_POST['Email']);
      $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
      if (mail($recipient, $subject, $msg))
         echo nl2br("<b>Message Sent:</b>
         To: $recipient
         Subject: $subject
         Message:
         $msg");
      else
         echo "Message failed to send";
}


// initialize a variable to
   // put any errors we encounter into an array
   $errors = array();
   // test to see if the form was actually
   // posted from our form
   $page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
   if (!ereg($page, $_SERVER['HTTP_REFERER']))
      $errors[] = "Invalid referer\n";
   // check to see if a name was entered
   if (!$_POST['Name'])
      // if not, add that error to our array
      $errors[] = "Name is required";
   // check to see if a subject was entered
   if (!$_POST['Subject'])
      // if not, add that error to our array
      $errors[] = "Subject is required";
   // check to see if a message was entered
   if (!$_POST['MsgBody'])
      // if not, add that error to our array
      $errors[] = "Message body is required";
   // if there are any errors, display them
   if (count($errors)>0){
      echo "<strong>ERROR:<br>\n";
      foreach($errors as $err)
        echo "$err<br>\n";
   } else {
      // no errors, so we build our message
      $recipient = 'admin@stockshoots.co.uk';
      $from = stripslashes($_POST['Name']);
      $subject = stripslashes($_POST['Subject']);
      $msg = "Message sent by $from\n
         ".stripslashes($_POST['MsgBody']);
      if (mail($recipient,$subject,$msg))
         echo "Thanks for your message!";
      else
         echo "An unknown error occurred.";
   }
   

// your actual page content ends here





pagefooter();
ob_end_flush();
?>
\

Logged

stock

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 109
Re: adding a fill in form on the site
« Reply #3 on: September 24, 2005, 05:29:56 am »

sorry if this isn't related to CPG. Do tell me and I will have to learn from the website, etc.

very thanks

Stock
Logged

stock

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 109
Re: adding a fill in form on the site
« Reply #4 on: September 24, 2005, 07:36:49 am »

I have now solved this problem, so please delete this question. thanks.

Stock
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47844
  • aka "GauGau"
    • gaugau.de
Re: adding a fill in form on the site
« Reply #5 on: September 24, 2005, 09:50:33 am »

we don't delete threads, they stay as reference for others. Why don't you post your solution, so others may benefit from your insight as well?
Logged

stock

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 109
Re: adding a fill in form on the site
« Reply #6 on: September 24, 2005, 03:36:46 pm »

Gau gau. Of course.

Here goes, though it's not perfect, doesn't function fully yet and you experts might think it is unwieldy, but here goes. It does generate a message sent to me at least! After trying out things for several hours last night, this is a milestone!

I created two files, one that contains my normal header and functioning and the form action written in html ( I haven't got round to tweaking this yet for design or content or even wording).This is the page my 'Contact us' button on the site will go to.

Then I created a file called mail.php (the first file needs this to generate the action) which holds my normal header and functioning then the php function to send the fom to me and error messages. Once the form has been sent, this will generate a new page saying. "Thank you for your message", etc. My only problem here is this seem to come up even if they haven't fill in anything, and the error message is not showing at all, but for now it work as I imagine most people will not press submit until they have filled in something. It does look like I'm missing some vital php functioning here. If someone could fill me in...

The two files contains the following:

The First file (called in my instance contactus.php)

Code: [Select]
<?php
define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');
pageheader('About whatever');
// your actual page content starts here

    
starttable("100%"'Content block title'1);
    
?>

   <tr>
    <td class="tableb" valign="top" align="center">
    lorum ipsum lorum ipsum Hello world and all that mock text
    </td>
    </tr>
    <?php
    endtable
();?>

   
   
<form action="mail.php" method="post">
     <table border="0" cellspacing="0" cellpadding="5">
         <tr>
            <br><td>Your name:</td>
            <td><input type="text" name="name" cols="60" rows="6"></td>
         </tr>
         <tr>
            <br><td>Email address</td>
            <td><input type="text" name="email" cols="60" rows="6"></td>
         </tr>
         <br><tr><td>Subject</td>
            <td><input type="text" name="subject" cols="60" rows="6"></td>
         </tr>
         <tr>
            <br><td valign="top">Message</td>
            <td><textarea name="message" cols="60" rows="6"></textarea></td>
         </tr>
         <tr>
            <td>&nbsp;</td>
            <br><td><input type="submit" value="Submit">
         <input type="reset" name="Reset" value="Reset"></tr></td>
      </table>
   </form>
   
<?php

// your actual page content ends here
pagefooter();
ob_end_flush();
?>



the second file (called in my instant mail.php) contains

Code: [Select]
<?php
define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');
pageheader('Thank you');
// your actual page content starts here

    
starttable("100%"'Content block title'1);
    
?>

   <tr>
    <td class="tableb" valign="top" align="center">
    lorum ipsum lorum ipsum Hello world and all that mock text
    </td>
    </tr>
    <?php
    endtable
();
    
    
    
    
   function 
checkOK($field)
{
if (
eregi("\r",$field) || eregi("\n",$field)){
die(
"Invalid Input!");
}
}

$name=$_POST['name'];
checkOK($name);
$name=$_POST['subject'];
checkOK($subject);
$email=$_POST['email'];
checkOK($email);
$comments=$_POST['message'];
checkOK($message);
$to="you@yourwebsite.co.uk";
$message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email";
if(
mail($to,"Comments From Your Site",$message,"From: $email\n")) {
echo 
"Thank you for your message. We'll get back to you asap";
} else {
echo 
"There was a problem sending the mail. Please check that you filled in the form correctly.";
}




// your actual page content ends here
pagefooter();
ob_end_flush();
?>




Hope there's something of use here

Stock
« Last Edit: September 25, 2005, 06:17:41 pm by GauGau »
Logged

antisa33

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 181
    • Free french kids coloring
Re: adding a fill in form on the site
« Reply #7 on: September 05, 2006, 11:29:33 pm »

Thanks STOCK, it is very usefull for me
Logged
Pages: [1]   Go Up
 

Page created in 0.023 seconds with 20 queries.