body{font-family: "Trebuchet MS"; font-size:11px; text-align:center; margin:0px; padding:0px; background-color:#ffffff;} form{padding:0px; margin:0px;} input, select{font-size:11px;} label{font-weight:bold;} td{vertical-align:text-bottom; padding:3px;border:1px solid #e5e5e5;} fieldset{padding:5px;} legend{font-size:14px; font-weight:bold; padding:0px 3px;} .error{padding:5px; background-color:#FFFFCC; border:1px solid #cc0014; color:#cc0014; font-size:12px; margin:5px;} .alert{vertical-align:middle; padding:3px; border:0px;} .form_error{background-color:#cc0014; border:1px solid #FFFFCC;} .clear{clear:both;} #form_div{padding:5px 10px; width:500px;} #download{background-color:#000000; border:3px solid #99CC00; padding:10px; margin:5px;}
$y){ $body .= $x != "submit" || $x != "image" || $x != "file" ? $x.": ".$y."\r\n" : ""; } //mail($to, $subject, $body, $headers); //NOW THAT WE ARE DONE WITH THE FORM REDIRECT //header("Location: URL", true); //exit(); //OR WRITE A MESSAGE echo "Thank you. Form was submitted...."; }else{//we have error so show the form again echo $ewd_form; } ?>
OR

) $f_after = as above but for closing tag (e.g. ,

) or
tag $f_validate = true OR false - true will require validation while false will NOT $f_error_msg = ERROR mesage if $f_validate = true OTHERWISE WILL BE IGNORED $f_xtra = xtra option to be added before closing tag (e.g onsubmit='some JS function' OR onchage='js function again' OR accesskey="1" tabindex="1" title="title" readonly="true") $f_src = for use with image buttons */ function ewd_form_fields($f_label='', $f_type='', $f_name, $f_id='', $f_size='', $f_maxlength='', $f_value='', $f_options='', $f_before='', $f_after='', $f_validate=false, $f_error_msg='', $f_xtra='',$f_src=''){ global $ewd_error_array,$ewd_error_top_array,$x_ewd_form_name; $ewd_form_field = ""; //lets see if we have the type of the field - if not text will be used $f_type = trim($f_type) == "" ? "text" : trim($f_type); //convert to lower the f_name and f_id $f_name = trim(strtolower(preg_replace("#[^0-9a-zA-Z\-\_]#","",$f_name))); $f_id = trim($f_id) != "" ? trim(strtolower(preg_replace("#[^0-9a-zA-Z\-\_]#","",$f_id))) : $f_name; //check the size of the field $f_size = trim(preg_replace("#[^0-9\,]#","",$f_size)) != "" ? $f_size : (($f_type == "text" || $f_type == "password") && $f_size == "" ? "30" : ""); //maxlength $f_maxlength = trim(preg_replace("#[^0-9]#","",$f_maxlength)); //check value from POST OR DEFAULT $f_value = ewd_get_post_value($f_value, $f_name,$f_type); //extra value to be added before closing tag $f_xtra = trim($f_xtra) != "" ? " ".$f_xtra : ""; //remove spaces img src for the button $f_src = trim($f_src) != "" ? $f_src : ""; //NOW LETS CREATE SOME FIELDS switch ($f_type){ case "text": $ewd_form_field = ""; break; case "password": $ewd_form_field = ""; break; case "hidden": $ewd_form_field = ""; break; case "submit": $ewd_form_field = ""; break; case "image": $ewd_form_field = $f_src != "" ? "" : ""; break; case "textarea": $f_size = stristr($f_size,",") ? explode(",",$f_size) : $f_size; if(is_array($f_size)){ $cols = $f_size[0]; $rows = $f_size[1]; }else{ $cols = "30"; $rows = "6"; } $ewd_form_field = ""; break; case "checkbox": $options = ewd_get_option_value($f_options); if(is_array($options)){ foreach($options as $x=>$y){ $y = explode("|",$y); $value = trim($y[0]); $text = !empty($y[1]) ? trim($y[1]) : $value; $ewd_form_field .= "".SPACES_CHECKBOX; } }else{ $y = explode("|",$y); $value = trim($y[0]); $text = !empty($y[1]) ? trim($y[1]) : $value; $ewd_form_field .= "$text: "; } break; case "radio": $options = ewd_get_option_value($f_options); if(is_array($options)){ foreach($options as $x=>$y){ $y = explode("|",$y); $value = trim($y[0]); $text = !empty($y[1]) ? trim($y[1]) : $value; $ewd_form_field .= "".SPACES_RADIO; } }else{ $y = explode("|",$y); $value = trim($y[0]); $text = !empty($y[1]) ? trim($y[1]) : $value; $ewd_form_field .= "$text: "; } break; case "select": case "select-multiple": $options = ewd_get_option_value($f_options); $ewd_form_field .= ""; break; case "file": $ewd_form_field = ""; break; default: $ewd_form_field = ""; }//end switch //ADD before and after if any and remove extra spaces but exclude textarea fields $ewd_form_field = $f_type != "textarea" ? preg_replace("#\s\s+#"," ",$f_before.$ewd_form_field.$f_after) : $f_before.$ewd_form_field.$f_after; //SHOW TABLE FORMAT OR DIVs if($f_type != "hidden"){ if(DIV_TBL == "table"){//we want TABLE $ewd_form_field = " $f_label".($f_type != "submit" ? ewd_get_field_required($f_validate) : "")." $ewd_form_field".($f_validate ? ewd_form_validate($f_name,$f_error_msg, $f_type,$f_label,$x_ewd_form_name) : "")." "; }else{ //we want DIVs $ewd_form_field = "
$f_label".($f_type != "submit" ? ewd_get_field_required($f_validate) : "")."
$ewd_form_field".($f_validate ? ewd_form_validate($f_name,$f_error_msg, $f_type,$f_label,$x_ewd_form_name) : "")."
"; } }//end if not hidden field return $ewd_form_field; } //START OF THE FORM function ewd_form_start($ewd_form_name, $ewd_form_id='', $ewd_form_action='', $ewd_form_xtra=''){ global $x_ewd_form_name; $x_ewd_form_name = "formid".$ewd_form_name; $ewd_form = "
"; //SET A UNIQUE ID FOR THE HIDDEN FIELD TO COOP WITH MORE THAN ONE FORM ON THE SAME PAGE $ewd_form .= ""; if(DIV_TBL == "table"){ $ewd_form .= ""; }else{ $ewd_form .= "
"; } return $ewd_form; } //END OF THE FORM function ewd_form_end(){ $ewd_form = (DIV_TBL == "table" ? "
" : "")."
"; return $ewd_form; } //get the posted value function ewd_get_post_value($f_value, $f_name,$f_type){ $str = trim($f_value);//default value if(!empty($_POST[$f_name])){ $str = trim($_POST[$f_name].($f_type == "select-multiple" ? "[]" : "")); } return $str; } //GET OPTION IF ANY function ewd_get_option_value($str){ $options = $str; if(stristr($str, "*")){ //we have more than 1 $options = explode("*",$str); } return $options; } //IS RQUIRED - SO ADD A * function ewd_get_field_required($str){ $str = $str === true ? " * " : ""; return $str; } //VALIDATE ID REQUIRED function ewd_form_validate($f_name,$f_error_msg='', $f_type,$f_label='',$x_ewd_form_name){ global $ewd_error_array,$ewd_error_top_array,$ewd_error_exist; $x_errors = ""; if(count($_POST)>0 && !empty($_POST[$x_ewd_form_name])){ if($f_type == "file"){ $str = !empty($_FILES[$f_name]['name']) ? trim($_FILES[$f_name]['name']) : ""; }else{ $str = !empty($_POST[$f_name]) ? trim($_POST[$f_name].($f_type == "select-multiple" ? "[]" : "")) : ""; } if($str == ""){ $ewd_error_top_array[] = "".($f_label != "" ? $f_label : $f_name)."".($f_error_msg != "" ? $f_error_msg : " is REQUIRED"); $ewd_error_array[] = $f_name; } $x_errors = ewd_f_form_errors($f_name, $ewd_error_array,$f_error_msg); } return $x_errors; } //SHOW FIELD ERROR function ewd_f_form_errors($f_name, $ewd_error_array,$f_error_msg=''){ $errors = (in_array($f_name, $ewd_error_array) ? ($f_error_msg != "" ? " ".$f_error_msg."" : " REQUIRES YOUR ATTENTION") : ''); return $errors; } //SHOW ERROR MESSAGE function ewd_show_error($ewd_error_array){ global $ewd_error_top_array,$x_ewd_form_name; $error = ""; if(empty($ewd_error_array)) return; if(isset($_POST[$x_ewd_form_name]) && !empty($_POST[$x_ewd_form_name])){ $error = "

We have found the following error while submitting your form...

"; foreach($ewd_error_array as $x=>$y){ $error .= $y."
"; } $error .= "
"; } //clear the array unset($ewd_error_array); unset($ewd_error_top_array); return $error; } //PARSE AND CREATE FULL URL function ewd_parse_url(){ /*** check for https ***/ $protocol = !empty($_SERVER['HTTPS']) ? 'https' : 'http'; /*** return the full address ***/ return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; } // END FUNCTION TO CREATE FORM FIELDS AND SHOW ERRORS ?>