Jump to content

Error while submitting email contact form


teramera

Recommended Posts

Hi!,

I am trying to get a php directory script to work and am getting a unique error.

When i enter text in the body field without using a enter key to break lines it works fine

 

d779b868a3.jpg

 

But when i enter text with multiple lines using the enter key to break lines or a sentence it gives an error and does not post.

 

c463f777d9.jpg

 

Can someone please help tell me how to get it to work. What sort of codes do I look for in the script since there are a large number of files and more importantly what do i need to change to get it to work.

 

 

All help greatly appreciated.

Thanks in advance for your time

Tera

Link to comment
Share on other sites

But when i enter text with multiple lines using the enter key to break lines or a sentence it gives an error and does not post.

 

What is the error?

feb8768254.jpg

 

Thats the only error I am getting. Can you pls tell me what string or someting to look for in the files so then I can post that relevant part here so you can peek into the code  and understand it better. Am a newbie so not know php.

 

Thanks

Tera

Link to comment
Share on other sites

Hi! rondog,

Sorry I couldnt figure out where to run that line for echo that you mentioned.

here is the code of the form part in the php page:

 

<form name="mail" method="post" action="<?=$_SERVER["PHP_SELF"]?>?id=<?=$_GET["id"]?>#info" class="formListingDetail">

 

<? foreach ($_GET as $key => $value) print "<input type=\"hidden\" name=\"$key\" value=\"$value\" />"; ?>

<input type="hidden" name="id" value="<?=$_GET["id"]?>" />

<input type="hidden" name="id" value="<?=$_GET["id"]?>" />

<input type="hidden" name="to" value="<?=htmlentities($listing->getString("email"))?>" />

<? if ($error) { ?>

<p class="<?=$message_style?>"><?=$error?></p>

<? } ?>

 

<a name="info"></a><p class="formListingTitle"><?=system_showText(LANG_LISTING_CONTACTTITLE)?></p>

 

<label for="from"><span class="required">*</span><?=system_showText(LANG_LABEL_YOUREMAIL)?></label>

<input type="text" name="from" id="from" value="<?=$from?>" />

<br />

<label for="subject"><?=system_showText(LANG_LABEL_SUBJECT)?></label>

<input type="text" name="subject" id="subject" value="<?=$subject?>" />

<br />

<label for="body"><span class="required">*</span> <?=system_showText(LANG_LABEL_ADDITIONALMSG)?></label>

<textarea name="body" rows="5" id="body" cols=""><?=$body?></textarea>

<br class="clear" />

<p class="formCaptchaWarning"><?=system_showText(LANG_LABEL_CAPTCHAHELP)?></p>

<div class="captchaImage"><span class="required">*</span><img src="<?=DEFAULT_URL?>/includes/code/captcha.php" border="0" alt="<?=system_showText(LANG_ALT_CAPTCHA)?>" title="<?=system_showText(LANG_TITLE_CAPTCHA)?>" /></div>

<input type="text" name="captchatext" value="" class="formCode" />

<ul class="standardButton">

<li>

<? if ($user){ ?>

<button type="submit" value="Send"><?=system_showText(LANG_BUTTON_SEND)?></button>

<? } else { ?>

<button type="button" value="Send"><?=system_showText(LANG_BUTTON_SEND)?></button>

<? } ?>

</li>

</ul>

<br class="clear" />

<!--[if IE]>

<br class="clear" />

<![endif]-->

 

</form>

 

Can you tell me where to add that line taht you gave me  so that we know about whats making the error.

 

Thanks Regards Tera

Link to comment
Share on other sites

man thats a mess. Try putting it above your form, but make sure its wrapped in php tags. Also, you should get in the habit of not doing short tags. Some servers don't support it which can cause errors, not saying that's your problem, but its good practice to do the full <?php //blah blah ?>

Link to comment
Share on other sites

Hi! rondog,

I entered the echo string which you gave me like this :

<?php echo $_POST['body']; ?>

above where the form part was and submitted the form:

 

 

While I entered the text in multiple lines using the ENter Key to break lines like this:

8143e4a9ef.jpg

 

the echo command came back looking like this with the text in one single line.

If I post in one single line then the worm work, but not the way when i enter it with breaks in lines.

Does this trow some more light on what I need to do... Look forward to your guidence.

Thanks once again

 

Regards

Tera.

Link to comment
Share on other sites

here's a cleaned up version of your code (it's not been error checked, just cleaned up to run faster, and be easier to read)

<?php
$id = $_GET['id'];
$hidden_fields = "";
foreach ($_GET as $key => $value) {
$hidden_fields .= "<input type=\"hidden\" name=\"$key\" value=\"$value\" />\n";
}
if ($error){
$error_input = "<p class=\"$message_style\">$error</p>\n";
}
else{
$error_input = "";
}
$email_to = htmlentities($listing->getString("email"));
$contact_title = system_showText(LANG_LISTING_CONTACTTITLE);
$your_email = system_showText(LANG_LABEL_YOUREMAIL);
$subject2 = system_showText(LANG_LABEL_SUBJECT);
$addtl_message = system_showText(LANG_LABEL_ADDITIONALMSG);
$captcha_help = system_showText(LANG_LABEL_CAPTCHAHELP);
$default_url = DEFAULT_URL;
$submit_button = system_showText(LANG_BUTTON_SEND);
$alt_captcha = system_showText(LANG_ALT_CAPTCHA);
$title_captcha = system_showText(LANG_TITLE_CAPTCHA);
if ($user){
$submit = "<button type=\"submit\" value=\"Send\">$submit_button</button>";
}
else{
$submit = "<button type=\"button\" value=\"Send\">$submit_button</button>";
}
echo <<<CHEESEBURGER
<form name="mail" method="post" action="?id=$id#info" class="formListingDetail">

         $hidden_fields
         <input type="hidden" name="id" value="$id" />
         <input type="hidden" name="id" value="$id" />
         <input type="hidden" name="to" value="$email_to" />
         $error_input
         <a name="info"></a><p class="formListingTitle">$contact_title</p>
         <label for="from"><span class="required">*</span>$your_email</label>
         <input type="text" name="from" id="from" value="$from" />
         <br />
         <label for="subject">$subject2</label>
         <input type="text" name="subject" id="subject" value="$subject" />
         <br />
         <label for="body"><span class="required">*</span> $addtl_message</label>
         <textarea name="body" rows="5" id="body" cols="">$body</textarea>
         <br class="clear" />
         <p class="formCaptchaWarning">$captcha_help</p>
         <div class="captchaImage"><span class="required">*</span><img src="$default_url/includes/code/captcha.php" border="0" alt="$alt_captcha" title="$title_captcha" /></div>
         <input type="text" name="captchatext" value="" class="formCode" />
         <ul class="standardButton">
            <li>
               $submit
            </li>
         </ul>
         <br class="clear" />
         <!--[if IE]>
         <br class="clear" />
         <![endif]-->

      </form>
CHEESEBURGER;
?>

*EDIT* Missed a couple system_showText's. fixed now

Link to comment
Share on other sites

Hi! jonsjava,

I tried your code what you gave me , but it still gives me the same error message and does not post.

 

Perhaps its something in the where the email posting code is in the scripts..... Can you guide me to find which file would be responsible for this part of the work.

 

Cause if i post the message all in one line then the form works.

 

Regards

tera

Link to comment
Share on other sites

Hi! jonsjava,

I tried your code what you gave me , but it still gives me the same error message and does not post.

 

Perhaps its something in the where the email posting code is in the scripts..... Can you guide me to find which file would be responsible for this part of the work.

 

Cause if i post the message all in one line then the form works.

 

Regards

tera

As I had said, I did no error checking. I just made it easier for other php freaks to help you out by making it easier to read.  Actually, we need to see what you process the form with, not just the form.

Link to comment
Share on other sites

Could the problem be somewhere in the form validator..... Here is the code from that file:

 


<?PHP

# ----------------------------------------------------------------------------------------------------
# * FILE: /class_formValidator.php
# ----------------------------------------------------------------------------------------------------

/**
* FormValidator
*
* This class validates forms nested in html files.
* It can validate fields on following criteria:
* - required field
* - content ( email, digit, alpha, word )
* - own perl or posix regular expression
* - length ( min, max, equal )
* - only defined values ( for select, radio and checkbox )
* - forbidden values
* - field values dependecies 
*    + value can only exist with other field(s)
*    + value must be equal to other field(s) ( eg. on pass verification )
*    + value must exists OR/XOR other value(s)
* - It handles fields named like an array ( eg. radiobox/checkbox )
* - It can highlight the badly validated fields ( with smarty templates )
* - It can return an array which information which fields were badly validated ( with field name, or logical name )
*
**/

/*
Description
Parameters of form elem that are being processed by the class

$elem = array (
	'name'         => string,  // all
	'type'         => string,  // text or select
	                           // text covers html types: text, textarea, hidden, password
	                           // select covers html types: select, checkbox and radio
	'label'        => string,  // field label ( eg. 'Phone number' )
	'required'     => boolean, // field must have value
	'cont'         => string,  // content type: email, word, alpha, digit
	'ereg'         => string,  // text, textarea
	'preg'         => string,  // text, textarea
	'len'          => integer, // accurate length
	'len_min'      => integer, // min length
	'len_max'      => integer, // max length
	'val_max'      => integer, // max value of an integer ( use with cont == digit )
	'val_min'      => integer, // min value of an integer ( use with cont == digit )
	'values'       => array;   // select accepted values
	'forbid'       => array;   // forbidden values that match other criteria
	'arr_size_min' => integer  // when field name is an array( eg. 'phones[]' )
	                           // minimum number of elements in array
	// Fields dependencies
	'eqal'         => mixed,   // array or string,
	                           // value of this field must be equal to value of field in array()
	                           // eg. in when there are two password boxes either array or string
	'with'         => mixed,   // array or string, value must exist with other value(s)
	'alt_or'       => mixed,   // array or string, at least one of fields must have a value
	'alt_xor'      => mixed    // array or string, only one field must have a value
	);
*/

class FormValidator {

	/**
	 * Form definition
	 * 
	 * @var array
	 * @access private
	 */
	var $elems = array();

	/**
	 * If error occured while validation
	 * 
	 * @var boolean
	 * @access private
	 */
	var $err = false;

	/**
	 * Validation status for each field
	 * 
	 * @var array
	 * @access private
	 */
	var $validElems = array();

	/**
	 * Fields that need dependency check
	 * 
	 * @var array
	 * @access private
	 */
	var $secPhase = array();

	/**
	 * Constructor
	 *
	 * @param mixed $elems form definition
	 * @access public
	 * @return void
	 */
	function FormValidator(&$elems) {
		if ( is_array($elems) ) {
			// hmm...
			is_array($elems[0]) ? $this->elems = $elems : $this->elems[] = $elems;
		}
	}

	/**
	 * Validates Form
	 *
	 * @param array $request - $_GET, $_POST, $_SESSION or other data
	 * @access public
	 * @return boolean true - validation OK, false - validation error
	 */
	function validate(&$request) {

		// validated elems
		$this->validElems = array();

		$this->err = false;

		// fields that needs dependency check
		$this->secPhase = array();

		foreach ( $this->elems as $e ) {

			$name = $e['name'];

			isset($e['label']) ? null : $e['label'] = null;

			// Field not present in html form
			if ( !isset($request[$name]) ) {
				if($e['required']){
					$this->_setError($name, $k, $v, $e['label']);
					continue;
				} else {
					$this->validElems[$name][$k] = array('value'=>$v,'validation'=>true,'label'=>$e['label']);			  
				}
			}

			$val = $request[$name];

			// If field name is an array ( eg. phones[] in example above )
			if ( is_array($val) ) {
				if ( !empty($e['arr_size_min']) && $e['arr_size_min'] > 0 ) {
					$c = 0;
					foreach($val as $v) {
						if ( !empty($v) ) {
							$c++;
						}
					}
					if ( $c < $e['arr_size_min'] ) {
						$this->_setError($name, $k, $v, $e['label']); continue;
					}
				}
			}

			// Each value is converted to an array
			else {
				$val = array($val);
			}

			foreach ( $val as $k => $v ) {

				if ( !empty($e['required']) && (empty($v) && $v != "0")) {
					$this->_setError($name, $k, $v, $e['label']); continue;
				} elseif ( empty($v) ) {
					$e['validated'] = true;
					$this->validElems[$name][$k] = array('value'=>$v,'validation'=>true,'label'=>$e['label']);
					continue;
				}

				if ( in_array($e['type'], array('text')) ) {
					if ( !empty($e['len']) && $e['len'] != strlen($v) ) {
					$this->_setError($name, $k, $v, $e['label']); continue;
					}
					if ( !empty($e['len_min']) && strlen($v) < $e['len_min'] ) {
						$this->_setError($name, $k, $v, $e['label']); continue;
					}
					if ( !empty($e['len_max']) && strlen($v) > $e['len_max'] ) {
						$this->_setError($name, $k, $v, $e['label']); continue;
					}
					if ( !empty($e['val_min']) && $v < $e['val_min'] ) {
						$this->_setError($name, $k, $v, $e['label']); continue;
					}
					if ( !empty($e['val_max']) && $v > $e['val_max'] ) {
						$this->_setError($name, $k, $v, $e['label']); continue;
					}
					if ( !empty($e['ereg']) && !ereg($e['ereg'], $v) ) {
						$this->_setError($name, $k, $v, $e['label']); continue;
					}
					if ( !empty($e['preg']) && !preg_match($e['preg'], $v) ) {
						$this->_setError($name, $k, $v, $e['label']); continue;
					}
					if ( !empty($e['forbid']) && in_array($v, $e['forbid']) ) {
						$this->_setError($name, $k, $v, $e['label']); continue;
					}
					if ( isset($e['cont']) && in_array($e['cont'], array('email', 'alpha', 'word', 'digit','date','money')) ) {
						$expr = ''; // just temporally
						// digits only
						if ( $e['cont'] == 'digit' ) {
							$expr = "/^\d*$/";
						}
						// email verify
						elseif ( $e['cont'] == 'email' ) {
							if ( !$this->verifyEmail($v) ) {
								$this->_setError($name, $k, $v, $e['label']); continue;
							}
						}
						elseif ( $e['cont'] == 'alpha' ) {
							$expr = "/^[a-zA-Z]*$/";
						}
						elseif ( $e['cont'] == 'word' ) {
							$expr = "/^\w*$/";
						}
						elseif ( $e['cont'] == 'date' ) {
							$expr = "/^(??:(?:0?[13578]|1[02])(\/|-)31)|(??:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(??:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(??:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/";
						}
						elseif ( $e['cont'] == 'money' ) {
							$expr = "/^[0-9]{1,}+[,,.][0-9]{2,2}$/";
						}
						// del first condition when class would be complete...
						if ( !empty($expr) && !preg_match($expr, $v) ) {
							$this->_setError($name, $k, $v, $e['label']); continue;
						}
					}
					if ( !empty($e['with']) ) {
						$this->secPhase[] = $e;
					}
					if ( !empty($e['equal']) ) {
						$this->secPhase[] = $e;
					}
					foreach ( array('with', 'equal', 'alt_or', 'alt_xor') as $eq ) {
						if ( !empty($e[$eq]) ) {
							$this->secPhase[] = $e;
							break;
						}
					}
				}

				elseif ( $e['type'] == 'select' ) {
					if ( isset($e['values']) && !in_array($v, $e['values'])  ) {
						$this->_setError($name, $k, $v, $e['label']); continue;
					}

					foreach ( array('with', 'equal', 'alt_or', 'alt_xor') as $eq ) {
						if ( !empty($e[$eq]) ) {
							$this->secPhase[] = $e;
							break;
						}
					}

				}

				// hmm...
				else {
					$this->_setError($name, $k, $v, $e['label']); continue;
				}

				$this->validElems[$name][$k] = array('value'=>$v,'validation'=>true,'label'=>$e['label']);

			}

		}

		$this->_validateSecondPhase($request);
		return $this->err;

	}

	/*
	 * Dependency check
	 *
	 * @param array array $request - $_GET, $_POST, $_SESSION or other data
	 * @access private
	 * @return void
	 */
	function _validateSecondPhase(&$request) {

		foreach ( $this->secPhase as $e ) {

			$name = $e['name'];
			$val = $request[$name];

			if ( !is_array($val) ) {
				$val = array($val);
			}

			foreach ( $val as $k => $v) {

				if ( isset($e['with']) && is_array($e['with']) ) {
					foreach ($e['with'] as $eq) {
						if ( !empty($v) && empty($this->validElems[$eq][$k]['value']) ) {
							$this->_setError($eq, $k, $v, $e['label']); continue;
						}
					}
				}
				elseif ( !empty($e['with']) && !empty($v) && empty($this->validElems[$e['with']][$k]['value']) ) {
					$this->_setError($e['with'], $k, $v, $e['label']); continue;
				}

				if ( isset($e['equal']) && is_array($e['equal']) ) {
					foreach ( $e['equal'] as $eq ) {
						if ( $v != $this->validElems[$eq][$k]['value'] ) {
							$this->_setError($name, $k, $v, $e['label']); continue;
						}
					}
				}
				elseif ( !empty($e['equal']) && $v != $this->validElems[$e['equal']][$k]['value'] ) {
					$this->_setError($name, $k, $v, $e['label']); continue;
				}

				if ( isset($e['alt_or']) && is_array($e['alt_or']) && empty($v) ) {
					$c = 0;
					foreach ( $e['alt_or'] as $eq ) {
						 empty($this->validElems[$e['alt_or']][$k]['value']) ? $c++ : null;
					}
					if ( $c == 0 ) {
						$this->_setError($name, $k, $v, $e['label']); continue;
					}
				}
				elseif ( !empty($e['alt_or']) && empty($v) && empty($this->validElems[$e['alt_or']][$k]['value']) ) {
					$this->_setError($e['with'], $k, $v, $e['label']); continue;
				}

				if ( isset($e['alt_xor']) && is_array($e['alt_xor']) ) {
					$c = 0;
					foreach ( $e['alt_xor'] as $eq ) {
						empty($this->validElems[$e['alt_xor']][$k]['value']) ? null : $c++;
					}

					if ( empty($v) && $c != 1 ) {
						$this->_setError($e['with'], $k, $v, $e['label']); continue;
					}
					elseif ( !empty($v) && $c > 0 ) {
						$this->_setError($e['with'], $k, $v, $e['label']); continue;
					}
				}
				elseif ( !empty($e['alt_xor']) ) {
					if ( empty($v) && empty($this->validElems[$e['alt_xor']][$k]['value']) ) {
						$this->_setError($e['with'], $k, $v, $e['label']); continue;
					}
					elseif ( !empty($v) && !empty($this->validElems[$e['alt_xor']][$k]['value']) ) {
						$this->_setError($e['with'], $k, $v, $e['label']); continue;
					}
				}

			}

		}

	}

	/**
	 * Email verification
	 * 
	 * @param string $email
	 * @access private
	 * @return boolean true if OK otherwise false
	 */
	function verifyEmail($email) {
		$expr = '/^(.+)@(([a-z0-9\.-]+)\.[a-z]{2,5})$/i';
		$uexpr = "/^[a-z0-9\~\!\#\$\%\&\(\)\-\_\+\=\[\]\;\:\'\"\,\.\/]+$/i";
		if (preg_match($expr, $email, $regs)) {
			$username = $regs[1];
			$host = $regs[2];
			//if (checkdnsrr($host, MX)) {
				if (preg_match($uexpr, $username)) {
					return true;
				} 
				else {
					return false;
				}
		} else {
			return false;
		}
	}

	/**
	 * WARNING !
	 * Function name will be changed in future releases
	 *
	 * Highlight field/text with Smarty - if you don't use smarty it's quite useless...
	 *
	 * 
	 * @param object $s - Smarty object
	 * @param string $class_name - a css class name to assign
	 * @access public
	 * @return void
	 */
	function assignErrorClass(&$s, $class_name) {
		foreach ( $this->validElems as $k => $v ) {
			foreach ( $v as $k1 => $v1) {
				if ( $v1[1] === false ) {
					$err_c[$k][$k1] = $class_name;
				}
			}
		}
		$s->assign('err_c', $err_c);
	}

	/**
	 *
	 * Setting error
	 * 
	 * @param string $name field name
	 * @param integer $k key value usually 0 until field name is an array ( eg. phones[])
	 * @param string $value field value
	 * @param string $label - field label
	 * @access private
	 * @return void
	 */
	function _setError($name, $k=0, $value = '', $label = '') {
		$this->validElems[$name][$k] = array('value'=>$value,'validation'=>false,'label'=>$label);
		$this->err = true;
	}

	/**
	 * get array with validation result
	 * 
	 * @access public
	 * @return array - array with validation result for each field
	 */
	function getValidElems() {
		return $this->validElems;	
	}

}

?>

Link to comment
Share on other sites

I take it you did not make this script, but either paid someone or inherited it.

 

Is this a new issue? When did it start happening, what did you change on the server?

 

That is a lot of code to go through without being able to test it to know what is happening.

 

Let us know the answer to those questions, thanks.

Link to comment
Share on other sites

I got this script from another friend, its the first time that i am trying to get it running on my end.

 

Any help would be much appreciated..

 

Regards

tera

 

 

Chances are it works, but his version of PHP is different from yours. If your friend created it I would ask them this question, as they would know the system in and out. It could literally take me, or anyone else on here hours just to find this bug in this code since we do not know it, and even then we are not guaranteed that it is the problem.

 

Probably not the answer you wanted, but yea. That is the realistic point of view.

Link to comment
Share on other sites

Hi! premiso, My friends server as well as mine are running the same version of php which is PHP Version 5.2.8, I just checked and we both are on the same hosting provider. So that should be the issue i guess.

 

I appreciate your concern , and am grateful for your help.

 

Thanks

tera

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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