Jump to content

form


signs

Recommended Posts

Sorry my knowledge about PHP is 0,01..

I made a website for someone and the form on contactspage uses PHP script.

It seems that my client wants only the comments to fill in, so no name, telephone ect. Only comments. It's just that the PHP script for this form doesn't work anymore of there is not the name field to fill in.

 

Anyone that can help me with a script that doesn't demand anything else but the -comment-field..?! Pleaz

Link to comment
https://forums.phpfreaks.com/topic/155160-form/
Share on other sites

Sorry the comments are in dutch...

 

<?php

error_reporting(E_ALL);

session_start();

class SimpelMail {

 

var $aAan = array(

array('Piet Jansen','[email protected]'),

array('Jan Pietersen','[email protected]')

);

/* Een lijstje met personen waar je naartoe kan sturen. Dat kan natuurlijk ook gewoon 1 persoon zijn, dan gooi je de 2e array gewoon weg en dan komt het allemaal goed */

 

var $aVelden = array(

// Velden die er in moeten komen:

// naam || verplicht (1=ja, 0=nee) || 0=text,1=textarea

array('Onderwerp',1,0), // LET OP, ONDERWERP MOET ER ALTIJD IN, oP NR 0!!!!! (dus gewoon laten staan)

array('Naam',1,0), // LET OP OOK LATEN STAAN!

array('E-mailadres',1,0),

 

// vanaf hier costum fields toevoegen! //

 

array('Website',0,0),

// tot hier

 

array('Bericht',1,1)

);

 

var $sPrefix = '[form]: '; // wat er standaard voor het onderwerp moet komen te staan (kun je dus ook leeglaten)

var $iSpam = 300; // stukje beveiliging dat je neit elke 1 seconde mail krijgt van dezelfde personen. Dit is in seconden.

var $sPage; // alleen veranderen als je pagina iets is zoals ?pagina=contact

var $bIsGelukt;

 

function Formulier() {

?>

<h1>Contact</h1>

<form method="post" action="<?= $this->sPage; ?>">

<table>

<?php

if(count($this->aAan) > 1)

{

?><tr><td>Aan:</td><td><select name="iAan"><?php

foreach($this->aAan as $iNr => $aData)

{ echo '<option value="'.$iNr.'">'.$aData[0].'</option>'; }

?></select></td></tr><?php

}

foreach($this->aVelden as $iKey=>$aValue) {

$sVal = (isset($_POST[$iKey])) ? htmlspecialchars($_POST[$iKey]) : '';

?><tr><td><?= $aValue[0]; ?>:</td><td><?php

if($aValue[2]==1) {

echo '<textarea name="'.$iKey.'" cols="60" rows="8">'.$sVal.'</textarea>';

}

else {

echo '<input type="text" name="'.$iKey.'" value="'.$sVal.'" />';

}

?></td></tr>

<?php

}

?>

<tr><td colspan="2"><input type="submit" value="Verzenden" /></td></tr>

</table>

</form>

<?php

}

 

function Mailen() {

$aErr = array();

 

if(isset($_SESSION['iSpam']) && $_SESSION['iSpam'] > time())

{ $aErr[] = 'To prevent spam your allowed only to send one message per '.$this->iSpam.' seconds.'; }

 

foreach($this->aVelden as $iKey => $aVeld) {

if($this->aVelden[$iKey][1]==1) {

if(strlen(trim($_POST[$iKey])) == 0)

{ $aErr[] = 'You '.$aVeld[0].' forgot.'; }

}

}

 

if(count($aErr)>0) {

echo 'Error<ul>';

foreach($aErr as $sFout)

{ echo '<li>'.$sFout.'</li>'; }

echo '</ul>';

}

else {

if(count($this->aAan)==1)

{ $sAan = $this->aAan[0][1]; }

else

{ $sAan = $this->aAan[$_POST['iAan']][1]; }

 

$sHeader = "To: ".$sAan."\r\n";

$sHeader .= "From: ".$_POST[1]." <".$_POST[2].">\r\n";

 

$sMail = '';

foreach($this->aVelden as $iKey => $aVeld)

{ $sMail .= $aVeld[0].': '.$_POST[$iKey]."\n"; }

 

if(!@mail($sAan,$this->sPrefix.$_POST[0],$sMail,$sHeader))

{ echo 'Didnt succeed';}

else

{

echo 'Mail send ';

$_SESSION['iSpam'] = time()+$this->iSpam;

$this->bIsGelukt = true;

}

}

}

 

function Contact() {

if($_SERVER['REQUEST_METHOD']=='POST') {

$this->Mailen();

}

 

if(!$this->bIsGelukt) {

$this->Formulier();

}

}

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">

<head>

<title>Contact</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>

<body>

<?php

$aClass = new SimpelMail;

$aClass->sPage = $_SERVER['PHP_SELF'];

$aClass->Contact();

?>

</body></html>

- - - - - - - -

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>

<meta name="description" content="description"/>

<meta name="keywords" content="keywords"/>

<meta name="author" content="author"/>

<link rel="stylesheet" type="text/css" href="default.css" media="screen"/>

<title>Bohemia ecotecture</title>

<style media="screen,projection" type="text/css">

 

    .contact {

font-size: 90%;

color: #000000;

line-height: 175%;

padding-left: 730px;

padding-top: 7px;

}

    </style>

</head>

 

<body>

 

<div class="outer-container">

 

<div class="inner-container">

 

<div class="header">

 

<div class="title">

 

<div align="right" id="contact">

  <p align="left" class="contact">Bohemia Ecotecture<br />

      SARL 1254773457437<br />

      0630394720<br />

      [email protected] </p>

    </div>

<div class="slogan">

  <div align="right" class="path"></div>

</div>

 

  </div>

 

</div>

 

<div class="main">

 

<div class="content"><form name="contactform" method="post" action="send_form_email.php">

  <p> </p>

  <table width="450px">

<tr>

  <td rowspan="6"><img src="img/pixel.gif" alt="" width="40" height="1" />  </tr>

<tr>

  <td valign="top">

  <label for="first_name">Name</label></td>

<td valign="top">

  <input  type="text" name="first_name" maxlength="50" size="35"> </td>

</tr>

<tr>

  <td valign="top"">

  <label for="last_name">Last Name</label> </td>

<td valign="top">

  <input  type="text" name="last_name" maxlength="50" size="35"> </td>

</tr>

<tr>

  <td valign="top">

  <label for="email">Email Address</label> </td>

<td valign="top">

  <input  type="text" name="email" maxlength="80" size="35"> </td>

</tr>

<tr>

  <td valign="top">

  <label for="telephone">Telephone Number</label> </td>

<td valign="top">

  <input  type="text" name="telephone" maxlength="30" size="35"> </td>

</tr>

<tr>

  <td valign="top">

  <label for="comments">Comments</label> </td>

<td valign="top">

  <textarea  name="comments" cols="30" rows="6"></textarea> </td>

</tr>

<tr>

<td style="text-align:center">

  <div align="right"><a href="http://www.freecontactform.com/email_form.php"></a> </div></td>

<td style="text-align:center"> </td>

<td style="text-align:center"><p> </p>

  <div align="left">

  <input name="submit" type="submit" value="Submit" />

</div></td>

</tr>

</table>

</form>

</div>

 

<p> </p>

<div class="navigation">

  <ul>

<li><a href="index.html">Home</a></li>

<li><a href="index.html">Services</a></li>

<li><a href="index.html">Projects</a></li>

<li><a href="index.html">Contact</a></li>

  </ul>

 

<h2> </h2>

  </div>

 

<div class="clearer"> </div>

 

</div>

 

<div class="footer"><span class="right">design by <a href="http://misscosmic.com">misscosmic </a></span>

 

<div class="clearer"></div>

 

</div>

 

</div>

 

</div>

 

</body>

 

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/155160-form/#findComment-816220
Share on other sites

<?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "Your email subject line";


function died($error) {
	// your error code can go here
	echo "We are very sorry, but there were error(s) found with the form your submitted. ";
	echo "These errors appear below.<br /><br />";
	echo $error."<br /><br />";
	echo "Please go back and fix these errors.<br /><br />";
	die();
}

// validation expected data exists
if(!isset($_POST['first_name']) ||
	!isset($_POST['last_name']) ||
	!isset($_POST['email']) ||
	//!isset($_POST['telephone']) ||
	!isset($_POST['comments'])) {
	died('We are sorry, but there appears to be a problem with the form your submitted.');		
}

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  if(!eregi($email_exp,$email_from)) {
  	$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
$string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$first_name)) {
  	$error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!eregi($string_exp,$last_name)) {
  	$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
  	$error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  $string_exp = "^[0-9 .-]+$";
  if(!eregi($string_exp,$telephone)) {
  	$error_message .= 'The Telphone Number you entered does not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
  	died($error_message);
  }
$email_message = "Form details below.\n\n";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

 

and this in the fieldspage:

 

Some otherthing total others thing and maybe totally not..

When I test the form myself I use a mail address that comes with my domainname.

When I upload the site for the client I uses a hotmail address. Does hotmail cause conflict in this form handling maybe?

 

Link to comment
https://forums.phpfreaks.com/topic/155160-form/#findComment-816236
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.