Jump to content

Contact form


Draxo
 Share

Recommended Posts

Hi, I'd be eternally grateful if someone could tell me where I'm going wrong with the coding for the php form.

 

Many thanks,

 

D

 

<form action="kontaktscript.php" method="post">
	<fieldset>
		<label for="name">Namn:</label>
		<input type="text" name="name"  id="name"/>

		<label for="name">Tel:</label>
		<input type="text" name="tel"  id="telephone"/>

		<label for="email">Email:</label>
		<input type="text" name="email" id="email"/>

		<label for="message">Meddelande:</label>
		<textarea id="message"></textarea>

		<input type="submit" value="Skicka" />

	</fieldset>
</form>

18384_.php

Link to comment
Share on other sites

Have left out the actual info about the website, google makes it bad for business if it links to this showing the webmaster doesn't know what he's doing, hopefully there will be enough info anyway.

 

<?PHP

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

#                                                    #

#                Forms To Go 4.3.3                  #

#            http://www.bebosoft.com/              #

#                                                    #

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

 

 

 

 

 

 

 

error_reporting(E_ERROR | E_WARNING | E_PARSE);

ini_set('track_errors', true);

 

function DoStripSlashes($fieldValue)  {

// temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6

if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {

  if (is_array($fieldValue) ) {

  return array_map('DoStripSlashes', $fieldValue);

  } else {

  return trim(stripslashes($fieldValue));

  }

} else {

  return $fieldValue;

}

}

 

function FilterCChars($theString) {

return preg_replace('/[\x00-\x1F]/', '', $theString);

}

 

 

if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {

$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];

} else {

$clientIP = $_SERVER['REMOTE_ADDR'];

}

 

$FTGNAME = DoStripSlashes( $_POST['NAME'] );

 

$FTGTel = DoStripSlashes( $_POST['TEL'] );

$FTGEmail = DoStripSlashes( $_POST['EMAIL'] );

$FTGMeddelande = DoStripSlashes( $_POST['MEDDELANDE'] );

 

 

 

$validationFailed = false;

 

 

# Include message in error page and dump it to the browser

 

if ($validationFailed === true) {

 

$errorPage = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Error</title></head><body>A <br /><br />Hälsningar,<br /><br />A</body></html>';

 

$errorPage = str_replace('<!--FIELDVALUE:NAME-->', $FTGNAME, $errorPage);

$errorPage = str_replace('<!--FIELDVALUE:TEL:-->', $FTGTEL, $errorPage);

$errorPage = str_replace('<!--FIELDVALUE:EMAIL:-->', $FTGEMAIL, $errorPage);

$errorPage = str_replace('<!--FIELDVALUE:MEDDELANDE-->', $FTGMEDDELANDE, $errorPage);

 

 

$errorList = @implode("<br />\n", $FTGErrorMessage);

$errorPage = str_replace('<!--VALIDATIONERROR-->', $errorList, $errorPage);

 

echo $errorPage;

 

}

 

if ( $validationFailed === false ) {

 

# Email to Form Owner

 

$emailSubject = FilterCChars("A");

 

$emailBody = "--FTG_BOUNDRY\n"

  . "Content-Type: text/plain; charset=\"UTF-8\"\n"

  . "Content-Transfer-Encoding: base64\n"

  . "\n"

  . chunk_split( base64_encode( "NAME : $FTGNAME\n"

  . "TEL : $FTGTEL\n"

  . "EMAIL : $FTGEEMAIL\n"

  . "MEDDELANDE : $FTGMEDDELANDE\n"

  . "-missing field name- : #-missing field name-#\n"

  . "" ) )

  . "\n"

  . "--FTG_BOUNDRY\n"

  . "Content-Type: text/html; charset=\"UTF-8\"\n"

  . "Content-Transfer-Encoding: base64\n"

  . "\n"

  . chunk_split( base64_encode( "<html>\n"

  . "<head>\n"

  . "<title></title>\n"

  . "</head>\n"

  . "<body>\n"

  . "NAME : $FTGNAME<br />\n"

  . "TEL : $FTGTEL<br />\n"

  . "EMAIL : $FTGEMAIL<br />\n"

  . "MEDDELANDE : $FTGMEDDELANDE<br />\n"

  . "</body>\n"

  . "</html>\n"

  . "" ) )

  . "\n"

  . "--FTG_BOUNDRY--";

  $emailTo = 'Ar <@>';

 

  $emailFrom = FilterCChars("@");

 

  $emailHeader = "From: $emailFrom\n"

  . "MIME-Version: 1.0\n"

  . "Content-Type: multipart/alternative; boundary=\"FTG_BOUNDRY\"\n"

  . "\n";

 

  mail($emailTo, $emailSubject, $emailBody, $emailHeader);

 

 

  # Include message in the success page and dump it to the browser

 

$successPage = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Success</title></head><body>A<a href="www/">A</a></body></html>';

 

$successPage = str_replace('<!--FIELDVALUE:NAME-->', $FTGNAME, $successPage);

 

$successPage = str_replace('<!--FIELDVALUE:TEL-->', $FTGTEL, $successPage);

$successPage = str_replace('<!--FIELDVALUE:EMAIL-->', $FTGEMAIL, $successPage);

$successPage = str_replace('<!--FIELDVALUE:MEDDELANDE-->', $FTGMEDDELANDE, $successPage);

 

echo $successPage;

 

}

 

?>

Link to comment
Share on other sites

Your form element names are different to that used in the php code.

As Thorpe said, your problem is here:

$FTGNAME = DoStripSlashes( $_POST['NAME'] );

$FTGTel = DoStripSlashes( $_POST['TEL'] );
$FTGEmail = DoStripSlashes( $_POST['EMAIL'] );
$FTGMeddelande = DoStripSlashes( $_POST['MEDDELANDE'] );

 

MEDDELANDE doesn't exist at all - in your form, this field has no name...

 

In your form, you need:

<label for="message">Meddelande:</label>
		<textarea id="message" name="meddelande"></textarea>

The others are all upper-case in your PHP script, and lower-case in your form.  Not sure if this makes a difference, but worth making them the same just in case...

Link to comment
Share on other sites

Thanks guys,

 

Have got it to show the name field now, the others are still blank, have transformed all form elements in the html to uppercase as there are too many elements in the php form which make me very confused as to which I would make lowercase otherwise. What could the problem be that makes the other fields blank, all names seem to match up now?

 

 

Link to comment
Share on other sites

<form action="kontaktscript.php" method="post">
	<fieldset>
		<label for="name">Namn:</label>
		<input type="text" name="NAME"  id="NAME"/>

		<label for="name">Tel:</label>
		<input type="text" name="TEL"  id="TEL"/>

		<label for="email">Email:</label>
		<input type="text" name="EMAIL" id="EMAIL"/>

		<label for="MEDDELANDE">Meddelande:</label>
		<textarea id="MEDDELANDE" name="MEDDELANDE"> </textarea>

		<input type="submit" value="Skicka" />

	</fieldset>
</form>

 

<?PHP
######################################################
#                                                    #
#                Forms To Go 4.3.3                   #
#             http://www.bebosoft.com/               #
#                                                    #
######################################################







error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);

function DoStripSlashes($fieldValue)  { 
// temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6
if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) { 
  if (is_array($fieldValue) ) { 
   return array_map('DoStripSlashes', $fieldValue); 
  } else { 
   return trim(stripslashes($fieldValue)); 
  } 
} else { 
  return $fieldValue; 
} 
}

function FilterCChars($theString) {
return preg_replace('/[\x00-\x1F]/', '', $theString);
}


if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}

$FTGNAME = DoStripSlashes( $_POST['NAME'] );

$FTGTel = DoStripSlashes( $_POST['TEL'] );
$FTGEmail = DoStripSlashes( $_POST['EMAIL'] );
$FTGMeddelande = DoStripSlashes( $_POST['MEDDELANDE'] );



$validationFailed = false;


# Include message in error page and dump it to the browser

if ($validationFailed === true) {

$errorPage = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Error</title></head><body>A <br /><br />A<br /><br />A</body></html>';

$errorPage = str_replace('<!--FIELDVALUE:NAME-->', $FTGNAME, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:TEL:-->', $FTGTEL, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:EMAIL:-->', $FTGEMAIL, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:MEDDELANDE-->', $FTGMEDDELANDE, $errorPage);


$errorList = @implode("<br />\n", $FTGErrorMessage);
$errorPage = str_replace('<!--VALIDATIONERROR-->', $errorList, $errorPage);

echo $errorPage;

}

if ( $validationFailed === false ) {

# Email to Form Owner
  
$emailSubject = FilterCChars("A");
  
$emailBody = "--FTG_BOUNDRY\n"
  . "Content-Type: text/plain; charset=\"UTF-8\"\n" 
  . "Content-Transfer-Encoding: base64\n"
  . "\n"
  . chunk_split( base64_encode( "NAME : $FTGNAME\n"
  . "TEL : $FTGTEL\n"
  . "EMAIL : $FTGEEMAIL\n"
  . "MEDDELANDE : $FTGMEDDELANDE\n"
  . "-missing field name- : #-missing field name-#\n"
  . "" ) )
  . "\n"
  . "--FTG_BOUNDRY\n"
  . "Content-Type: text/html; charset=\"UTF-8\"\n"
  . "Content-Transfer-Encoding: base64\n"
  . "\n"
  . chunk_split( base64_encode( "<html>\n"
  . "<head>\n"
  . "<title></title>\n"
  . "</head>\n"
  . "<body>\n"
  . "NAME : $FTGNAME<br />\n"
  . "TEL : $FTGTEL<br />\n"
  . "EMAIL : $FTGEMAIL<br />\n"
  . "MEDDELANDE : $FTGMEDDELANDE<br />\n"
  . "</body>\n"
  . "</html>\n"
  . "" ) )
  . "\n"
  . "--FTG_BOUNDRY--";
  $emailTo = 'A <@>';
   
  $emailFrom = FilterCChars("@");
   
  $emailHeader = "From: $emailFrom\n"
   . "MIME-Version: 1.0\n"
   . "Content-Type: multipart/alternative; boundary=\"FTG_BOUNDRY\"\n"
   . "\n";
   
  mail($emailTo, $emailSubject, $emailBody, $emailHeader);
  
  
  # Include message in the success page and dump it to the browser

$successPage = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Success</title></head><body>A<a href="www/">A</a></body></html>';

$successPage = str_replace('<!--FIELDVALUE:NAME-->', $FTGNAME, $successPage);

$successPage = str_replace('<!--FIELDVALUE:TEL-->', $FTGTEL, $successPage);
$successPage = str_replace('<!--FIELDVALUE:EMAIL-->', $FTGEMAIL, $successPage);
$successPage = str_replace('<!--FIELDVALUE:MEDDELANDE-->', $FTGMEDDELANDE, $successPage);

echo $successPage;

}

?>

Link to comment
Share on other sites

Variable names in PHP are case sensitive...

 

You have:

$FTGNAME = DoStripSlashes( $_POST['NAME'] );

$FTGTel = DoStripSlashes( $_POST['TEL'] );
$FTGEmail = DoStripSlashes( $_POST['EMAIL'] );
$FTGMeddelande = DoStripSlashes( $_POST['MEDDELANDE'] );

So, your variables here are: $FTGNAME, $FTGTel, $FTGEmail and $FTGMeddelande

 

then you try to use them:

$errorPage = str_replace('<!--FIELDVALUE:NAME-->', $FTGNAME, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:TEL:-->', $FTGTEL, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:EMAIL:-->', $FTGEMAIL, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:MEDDELANDE-->', $FTGMEDDELANDE, $errorPage);

and further down:

  . chunk_split( base64_encode( "NAME : $FTGNAME\n"
  . "TEL : $FTGTEL\n"
  . "EMAIL : $FTGEEMAIL\n"
  . "MEDDELANDE : $FTGMEDDELANDE\n"

where (in both cases) you are looking for $FTGNAME, $FTGTEL, $FTGEMAIL and $FTGMEDDELANDE.

 

$FTGNAME matches the variable name from the $_POST line.  The other three will be blank because, as far as PHP is concerned, they are different variables, just as if they were different names.

 

For example:

$i = 5;
$I = 10;
print $i;

would output 5, not 10...

 

If you change the variable names to caps here, it should cure your program:

$FTGNAME = DoStripSlashes( $_POST['NAME'] );

$FTGTEL = DoStripSlashes( $_POST['TEL'] );
$FTGEMAIL = DoStripSlashes( $_POST['EMAIL'] );
$FTGMEDDELANDE = DoStripSlashes( $_POST['MEDDELANDE'] );

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

 Share

×
×
  • 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.