php - noob: display err_msg on page (pt. 2) -


i posted yesterday, apologize if responded , frustrated @ seeing again! form isn't working @ now, , i'd appreciate in solving problem.

i have form sends data database, , requires validation. yesterday @ least validating correctly, today can't hook action page correctly. here 2 pages:

page w/ form:

    <?php     session_start();     $form_field =   array(                                   'first_name'                =>  '',                                 'last_name'             =>  '',                                 'business_name'             =>  '',                                 'phone_number'              =>  '',                                 'web_address'               =>  '',                                 'email_address'             =>  '',                                 'how_selling_product'           =>  '',                                 'where_did_you_hear_about_us'   =>  '',                             );     foreach($form_field $key => $value){$profiledata[$key]='';}                    if(!empty($_session['profiledata'])){            $profiledata    =   $_session['profiledata'];     }      ?>      [js]     function mm_findobj(n, d) { //v4.01       var p,i,x;  if(!d) d=document; if((p=n.indexof("?"))>0&&parent.frames.length) {         d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}       if(!(x=d[n])&&d.all) x=d.all[n]; (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];       for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=mm_findobj(n,d.layers[i].document);       if(!x && d.getelementbyid) x=d.getelementbyid(n); return x;     }      function mm_validateform() { //v4.0       var i,p,q,nm,test,num,min,max,errors='',args=mm_validateform.arguments;        errors    += addvalidation("req","first_name","- first name required.");       errors    += addvalidation("req","last_name","- last name required.");        (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=mm_findobj(args[i]);         if (val) { nm=val.name; if ((val=val.value)!="") {           if (test.indexof('isemail')!=-1) { p=val.indexof('@');             if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain e-mail address.\n';           } else if (test!='r') { num = parsefloat(val);             if (isnan(val)) errors+='- '+nm+' must contain number.\n';             if (test.indexof('inrange') != -1) { p=test.indexof(':');               min=test.substring(8,p); max=test.substring(p+1);               if (num<min || max<num) errors+='- '+nm+' must contain number between '+min+' , '+max+'.\n';         } } } else if (test.charat(0) == 'r') errors += '- '+nm+' required.\n'; }       }         errors    += addvalidation("req","security_code","- security code required.");         if(!errors){         errors += addvalidation("valid_lastname","first_name","- please enter valid first name");         errors += addvalidation("valid_lastname","last_name","- please enter valid last name");         errors += addvalidation("numhyphenbrace","phone number","- please enter valid phone number");         errors += addvalidation("valid_url","web address","- please enter valid web address");         errors += addvalidation("email","email address","- please enter valid email");        }       if (errors) alert('the following error(s) occurred:\n'+errors);       document.mm_returnvalue = (errors == '');     }     [/js]      <h1>some content</h1>     <p>some text</p>      <form id="form1" name="form1" method="post" action="mailform" onsubmit="mm_validateform('name','','r','business name','','r','email address','','r','how selling product','','r','where did hear us','','r');return document.mm_returnvalue">         <div style="color:#ff0000; text-align:center;"><?php if(!empty($_get['err_msg'])){echo $_get['err_msg'];} ?></div>             <fieldset>                         <legend>contact form</legend>                     <p class="first">                         <label for="name">first name</label>                         <input type="text" name="first name" id="first_name" size="30" value="<?=htmlentities($profiledata['first_name'])?>" />                     </p>                             <p class="first">                         <label for="name">last name</label>                         <input type="text" name="last name" id="last_name" size="30" value="<?=htmlentities($profiledata['last_name'])?>" />                     </p>                                     <p>                         <label for="name">phone number</label>                         <input type="text" name="phone number" id="phone number" size="30" value="<?=$profiledata['phone_number']?>" />                     </p>                     <p>                         <label for="email">business name</label>                         <input type="text" name="business name" id="business name" size="30" value="<?=htmlentities($profiledata['business_name'])?>" />                     </p>                     <p>                         <label for="email">web address</label>                         <input type="text" name="web address" id="web address" size="30" value="<?=$profiledata['web_address']?>" />                     </p>                     <p>                         <label for="email">email</label>                         <input type="text" name="email address" id="email address" size="30" value="<?=$profiledata['email_address']?>" />                     </p>                         </fieldset>             <fieldset>                                                                                               <p>                         <label for="message">describe how plan on selling product</label>                         <textarea name="how selling product" id="how selling product" cols="30" rows="4"><?=htmlentities($profiledata['how_selling_product'])?></textarea>                     </p>                         <p>                         <label for="message">where did hear us?</label>                         <textarea name="where did hear us" id="where did hear us" cols="30" rows="4"><?=htmlentities($profiledata['where_did_you_hear_about_us'])?></textarea>                     </p>                             <p>                                 <img src="captchasecurityimages.php?width=100&height=40&characters=5" /><br />                         <label for="security_code">security code: </label><input id="security_code" name="security_code" type="text" />                             </p>                             </fieldset>                 <p class="submit"><button type="submit">send</button></p>                 <input name="mailform_address" type="hidden" value="email@address.com" />     </form> 

mailform.php success:

<?php  session_start();  include("connect.php");  function valid_email($str) {     return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? false : true; }  function is_url($str) {     return ( ! preg_match("/^((www)\.)?((\w+|[\d]?+)+(\.|\-)(\w+[\d]?+))+(\w)$/", $str)) ? false : true; }  function valid_phone($str) {     $num = $str;     $num = ereg_replace("([     ]+)","",$num);;     $num = eregi_replace("(\(|\)|\-|\+)","",$num);     if(!is_numeric($num))     {                return false;     }        else         return true; }  $form_field =   array(                               'first_name'                    =>  '',                             'last_name'                     =>  '',                             'business_name'                 =>  '',                             'phone_number'                  =>  '',                             'web_address'                   =>  '',                             'email_address'                 =>  '',                             'how_selling_product'           =>  '',                             'where_did_you_hear_about_us'   =>  '',                         ); foreach($form_field $key => $value){$profiledata[$key]=trim($_post[$key]);}  $_session['profiledata']    =   $profiledata;  $emailto = null; $emailmessage = "dealer contact form\n"; $emailsubject = "dealer contact form";  if(!empty($_post)){      //echo "<pre>";print_r($_post);die;      if( $_session['security_code'] != $_post['security_code'] || empty($_session['security_code'] ) ) {          // insert code showing error message here         $err_msg    = 'sorry, have provided invalid security code';         header("location: reseller.php?err_msg=".urlencode($err_msg));         return;      } else {         unset($_session['security_code']);       }      $fname      =   html_entity_decode(trim($_post['first_name']));     $lname      =   html_entity_decode(trim($_post['last_name']));     $company    =   html_entity_decode(trim($_post['business_name']));     $phone      =   html_entity_decode(trim($_post['phone_number']));     $website    =   html_entity_decode(trim($_post['web_address']));     $email      =   html_entity_decode(trim($_post['email_address']));     $notes      =   "lead source: ".html_entity_decode(trim($_post['where_did_you_hear_about_us']))."\n";     $notes      .=  "selling method: ".html_entity_decode(trim($_post['how_selling_product']));      if(!valid_phone($phone)){         $err_msg    = 'please enter valid phone number.';         header("location: reseller.php?err_msg=".urlencode($err_msg));         return;     }      if(!is_url($website)){         $err_msg    = 'please enter valid web address.';         header("location: reseller.php?err_msg=".urlencode($err_msg));         return;     }      if(!valid_email($email)){         $err_msg    = 'please enter valid email.';         header("location: reseller.php?err_msg=".urlencode($err_msg));         return;     }      if(!stristr($website,"http://") && !stristr($website,"https://") && $website){         $website    =   "http://".$website;     }      $res    =   mysql_query("select in_customer_id tbl_customer st_company_name = '".addslashes($company)."'");     if(mysql_num_rows($res)){            $err_msg    =   'business name exists';         header("location: reseller.php?err_msg=".urlencode($err_msg));         return;     }      $res    =   mysql_query("select st_user_name,st_user_email_id tbl_admin_user st_user_email_id='".addslashes($email)."' , flg_is_delete=0");     if(mysql_num_rows($res)){            $err_msg    =   'email exists';         header("location: reseller.php?err_msg=".urlencode($err_msg));         return;     }      $sql_customer   =   "insert tbl_customer (`st_company_name`, `in_customer_type`, `st_customer_account`, `in_customer_phone_number`, `flg_customer_account_type`, `flg_disable_ordering`,  `st_message`, `in_status`, `dt_added_date`, `st_web`, `st_notes`) values ('".addslashes($company)."', '2', '".time()."', '".addslashes($phone)."', '0', '1', 'you inquiry customer', '0', '".date("y-m-d h:i:s")."', '".addslashes($website)."', '".addslashes($notes)."')";      mysql_query($sql_customer);     $cust_id        =   mysql_insert_id();      if($cust_id){         $sql_user       =   "insert tbl_admin_user (`st_user_first_name`, `st_user_last_name`, `st_user_company_name`, `st_user_email_id`, `in_customer_id`) values ('".addslashes($fname)."', '".addslashes($lname)."', '".addslashes($company)."', '".addslashes($email)."', '".$cust_id."')";         mysql_query($sql_user);          $msg    =   "";         $sub    =   "thank contacting us.";          ob_start();         include("mailformat.php");         $msg =  ob_get_contents();         ob_end_clean();          $headers    =   '';          //$headers = "mime-version: 1.0\r\n";                        $headers .= "content-type:text/html;charset=iso-8859-1" . "\r\n";         $headers .= "from: " . $_post['mailform_address'] . "\r\n";         $headers .= "reply-to: ". $_post['mailform_address'] . "\r\n";         $headers .= "bcc: email@address.com";          if (@mail($email, $sub, $msg, $headers))         {             session_unset('profiledata');         }     }      foreach($_post $name => $value)     {         if ($name == 'mailform_address')         {             $emailto = $value;         }         elseif($name    !=  "security_code")         {             $emailmessage .= $name . ": " . $value . "\n";         }     }     session_unset('profiledata'); }  ?>      <?                     if (@mail($emailto, $emailsubject, $emailmessage))         {         ?> <p>we'll in touch within 2 business days.  if haven't heard within 2 business days, please <a href="contact">contact us</a></p>     <?         }         else         {         ?>     <p>e-mail not sent. please <a href="contact">contact us</a>.</p>            <?         }         ?> 

thanks helping me out.

i admit haven't read code thoroughly, of these might problem:

  1. in call mm_validateform() in script, think need pass names of html form fields though every argument seems correct, first 1 'name' doesn't seem valid form field.

  2. what function addvalidation() in mm_validateform() , do? since not see definition, assume might generating errors in js.

  3. in mm_validateform(), after line no. 3 & 4, seems variable errors never empty , preventing form submit?

i'm not clear @ point stuck - form not submitting @ all? did try alert of errors variable @ end of mm_validateform(). perhaps might help.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

c# - SharpSVN - How to get the previous revision? -

php cli reading files and how to fix it? -