php - noob: display err_msg on page -


i have form populates database, , i'm having trouble error handling. want errors show in small pop window on same pg.

    <form id="form1" name="form1" method="post" action="mailform.php" 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>         <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>         <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>                             </fieldset>         <p class="submit"><button type="submit">send</button></p>          <input name="mailform_address" type="hidden" value="email@address.com" />    </form> 

error handling:

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;     } 

i'd appreciate or @ least nudge in right direction. thanks!

depending on kind of 'popup' want, want implement client side javascript displays nicely formatted message makes use of message send server.

i'd @ using jquery if me.


Comments

Popular posts from this blog

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

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

url - Querystring manipulation of email Address in PHP -