Note that there are some explanatory texts on larger screens.

plurals
  1. POContact form doesn't send if there is a space in name PT 2
    primarykey
    data
    text
    <p>Ok, so here is my last question <a href="https://stackoverflow.com/questions/16124918/contact-form-doesnt-send-if-there-is-a-space-in-name">Contact form doesn't send if there is a space in name</a>, I have accepted an answer, but now there's a new problem (kinda). I am making a new thread, because the code is changed. So I have made the contact form to send email if there is a space in the name, even two spaces ("John Smith" and "John James Smith") are now acceptable, but if there is a space before the name or after the name ("John Smith " or " John Smith") it doesn't send. I know that nobody writes his name with a space at the beggining or at the end, but someone might press it accidentally, so how can I correct it? Here is the edited code</p> <pre><code>&lt;?php function sendemail($toname, $toemail, $fromname, $fromemail, $subject, $message, $type = "plain", $cc = "", $bcc = "") { require_once "class.phpmailer.php"; $mail = new PHPMailer(); $mail-&gt;IsMAIL(); $mail-&gt;CharSet = "UTF-8"; $mail-&gt;From = $fromemail; $mail-&gt;FromName = $fromname; $mail-&gt;AddAddress($toemail, $toname); $mail-&gt;AddReplyTo($fromemail, $fromname); if ($cc) { $cc = explode(", ", $cc); foreach ($cc as $ccaddress) { $mail-&gt;AddCC($ccaddress); } } if ($bcc) { $bcc = explode(", ", $bcc); foreach ($bcc as $bccaddress) { $mail-&gt;AddBCC($bccaddress); } } if ($type == "plain") { $mail-&gt;IsHTML(false); } else { $mail-&gt;IsHTML(true); $mail-&gt;Subject = $subject; $mail-&gt;Body = $message; if(!$mail-&gt;Send()) { $mail-&gt;ErrorInfo; $mail-&gt;ClearAllRecipients(); $mail-&gt;ClearReplyTos(); return false; } else { $mail-&gt;ClearAllRecipients(); $mail-&gt;ClearReplyTos(); return true; } } } function descript($text, $striptags = true) { // Convert problematic ascii characters to their true values $search = array("40","41","58","65","66","67","68","69","70", "71","72","73","74","75","76","77","78","79","80","81", "82","83","84","85","86","87","88","89","90","97","98", "99","100","101","102","103","104","105","106","107", "108","109","110","111","112","113","114","115","116", "117","118","119","120","121","122" ); $replace = array("(",")",":","a","b","c","d","e","f","g","h", "i","j","k","l","m","n","o","p","q","r","s","t","u", "v","w","x","y","z","a","b","c","d","e","f","g","h", "i","j","k","l","m","n","o","p","q","r","s","t","u", "v","w","x","y","z" ); $entities = count($search); for ($i=0; $i &lt; $entities; $i++) { $text = preg_replace("#(&amp;\#)(0*".$search[$i]."+);*#si", $replace[$i], $text); } $text = preg_replace('#(&amp;\#x)([0-9A-F]+);*#si', "", $text); $text = preg_replace('#(&lt;[^&gt;]+[/\"\'\s])(onmouseover|onmousedown|onmouseup|onmouseout|onmousemove|ondblclick|onfocus|onload|xmlns)[^&gt;]*&gt;#iU', "&gt;", $text); $text = preg_replace('#([a-z]*)=([\`\'\"]*)script:#iU', '$1=$2nojscript...', $text); $text = preg_replace('#([a-z]*)=([\`\'\"]*)javascript:#iU', '$1=$2nojavascript...', $text); $text = preg_replace('#([a-z]*)=([\'\"]*)vbscript:#iU', '$1=$2novbscript...', $text); $text = preg_replace('#(&lt;[^&gt;]+)style=([\`\'\"]*).*expression\([^&gt;]*&gt;#iU', "$1&gt;", $text); $text = preg_replace('#(&lt;[^&gt;]+)style=([\`\'\"]*).*behaviour\([^&gt;]*&gt;#iU', "$1&gt;", $text); if ($striptags) { do { $thistext = $text; $text = preg_replace('#&lt;/*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^&gt;]*&gt;#i', "", $text); } while ($thistext != $text); } return $text; } $name=0; $telefon=0; $sender=0; $syobshtenie=0; $ename=0; $etelefon=0; $esender=0; $esyobshtenie=0; if($_POST['name']){ $name = $_POST['name']; if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $sender)) { $sender="Име"; } } else { $name=1; $ename=1; } if($_POST['sender']){ $sender = $_POST['sender']; if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $sender)) { $sender="Email"; } } else { $sender=1; $esender=1; } if($_POST['telefon']){ $telefon = $_POST['telefon']; } if($_POST['zapitvane']){ $zapitvane = $_POST['zapitvane']; $syobshtenie = "&lt;p&gt;Запитване от ".$_POST['name']." &lt;br /&gt;Email: ".$sender." &lt;br /&gt;Телефон: ".$telefon."&lt;/p&gt;".$zapitvane; } else { $syobshtenie=1; $esyobshtenie=1; } if($name=="Име"){ $ename=1; } if($telefon=="Телефон"){ $etelefon=1; } if($sender=="Email"){ $esender=1; } if($syobshtenie=="Моля, въведете съобщение до нас"){ $esyobshtenie=1; } if($ename==0 &amp;&amp; $esender==0 &amp;&amp; $esyobshtenie==0 &amp;&amp; $etelefon==0){ sendemail("VillaDes", "info@konsumator.com", "", $sender, $name, $syobshtenie, "", "", ""); echo ' &lt;div class="active-error"" style="margin-top:5px;"&gt;Съобщението Ви беше изпратено.&lt;br /&gt;&lt;br /&gt;Приятен ден!&lt;/div&gt; &lt;script&gt; document.getElementById("contact").reset(); &lt;/script&gt;'; } else { echo ' &lt;div class="border-15"&gt;&lt;/div&gt;&lt;div class="active-error"&gt;&lt;b&gt;Моля, въведете:&lt;/b&gt;&lt;/div&gt;&lt;div class="border-8"&gt;&lt;/div&gt;'; if($ename==1) { echo '&lt;div class="active-error"&gt;Име&lt;/div&gt;&lt;div class="border-8"&gt;&lt;/div&gt;'; } if($esender==1) { echo '&lt;div class="active-error"&gt;Е-поща&lt;/div&gt;&lt;div class="border-8"&gt;&lt;/div&gt;'; } if($etelefon==1) { echo '&lt;div class="active-error"&gt;Телефон&lt;/div&gt;&lt;div class="border-8"&gt;&lt;/div&gt;'; } if($esyobshtenie==1) { echo '&lt;div class="active-error"&gt;Запитване&lt;/div&gt;'; } } echo '&lt;script type="text/javascript"&gt; $(document).ready(function() { $("#close-email").click(function () { $("#mailresult").hide("fast"); } ); }); &lt;/script&gt;'; ?&gt; </code></pre> <p>and this is the problematic part, the name, where something has to be done in order to accept any number and position of spaces or other symbols</p> <pre><code>if($_POST['name']){ $name = $_POST['name']; if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $sender)) { $sender="Име"; } } else { $name=1; $ename=1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload