查看: 1805|回复: 25
|
请问怎样在submit form之前跳出confimation box??
[复制链接]
|
|
这是submit的按钮,请问怎样在submit form之前跳出confimation box
我想加这个
http://www.w3schools.com/jsref/t ... me=tryjsref_confirm
这是submit button
- <div class='container'>
- <input type='submit' name='Submit' value='Submit' />
- </div>
复制代码
这是confirmation pop up
- <html>
- <body>
- <p>Click the button to display a confirm box.</p>
- <button onclick="myFunction()">Try it</button>
- <script>
- function myFunction() {
- confirm("Press a button!");
- }
- </script>
- </body>
- </html>
复制代码 应该如何加进去才能实现在confirmation box按OK就SUBMIT,按Cancel就取消submit form?
或者有没有更简单的方法??
我只是初学者。
|
|
|
|
|
|
|
|
发表于 26-9-2015 03:14 PM
|
显示全部楼层
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title></title>
- </head>
- <body>
- <form action="HtmlPage.html" onsubmit="onSubmit(event)">
- <input type="text" value="keatkeat" />
- <input type="submit" />
- </form>
- <script>
- function onSubmit(e) {
- if (!confirm("sure bo ? you want submit meh ?")) {
- e.preventDefault(); //阻止事件进行
- }
- }
- </script>
- </body>
- </html>
复制代码
拦截 onSubmit 事件.
当然方法很多啦.
去问老师吧。
如果是自学没老师问的话,那先去找个老师吧。
|
|
|
|
|
|
|
|
发表于 26-9-2015 03:16 PM
|
显示全部楼层
- <form method="post" onsubmit="return confirm('Are you sure you want to submit?');">
- <input type='submit' name='Submit' value='Submit' />
- </form>
复制代码 |
|
|
|
|
|
|
|
发表于 26-9-2015 09:35 PM
|
显示全部楼层
本帖最后由 musicalangel 于 26-9-2015 10:27 PM 编辑
首先你要分辨出 html 裡面 button 跟 submit 是兩個完全不同的東西,
最大的差別是, submit 必須跟 form 的tag裡面, 然後 submit 一但按下後, form 就會送出,
而button 可以單獨存在, 然後用event handler 來指定他被按下後, 要執行甚麼動作.
我先顯示以 submit 為基礎的code
HTML:
- <form id="form1" name="form1" method="POST">
- <input type="submit" id="submit_btn" name="submit_btn" value="Send">
- </form>
复制代码
Javascript:
- $(function() {
- $("#form1").submit(function(e){ /*綁定form1在執行 submit的時候要執行以下的動作 */
- if(!confirm("Press a button")) /* 如果在 confirm box 裡面按了Cancel */
- {
- e.preventDefault(); /* 取消掉form1 的 submit*/
- }
- });
- });
复制代码
PS:你必須注意, 這個example 我有使用JQuery
你可以在這裡測試:
https://jsfiddle.net/g9tqckgL/
如果你還是面對著submit 時沒有辦法停下submit
有幾方面你是要注意的
- 你的停止submit event 的語法不對 例如上面所顯示的 e.preventDefault
- 或者是你的comfirm沒有寫對, 例如少了個 驚嘆號(!)
- 你把submit 跟 button 搞錯了.
我建議你把你的code 帖出來, 這樣大家比較容以幫到你.
祝學習愉快.
|
|
|
|
|
|
|
|

楼主 |
发表于 26-9-2015 09:47 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 26-9-2015 09:47 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 27-9-2015 03:20 AM
|
显示全部楼层
本帖最后由 chew2293 于 27-9-2015 03:27 AM 编辑
这是form
- <?PHP
- /*
- Contact Form from HTML Form Guide
- This program is free software published under the
- terms of the GNU Lesser General Public License.
- See this page for more info:
- http://www.html-form-guide.com/contact-form/contact-form-attachment.html
- */
- require_once("./include/fgcontactform.php");
- $formproc = new FGContactForm();
- //1. Add your email address here.
- //You can add more than one receipients.
- $formproc->AddRecipient('tests@html-form-guide.com'); //<<---Put your email address here
- //2. For better security. Get a random tring from this link: http://tinyurl.com/randstr
- // and put it here
- $formproc->SetFormRandomKey('HG9hPBpn9Bn26yg');
- $formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024);
- if(isset($_POST['submitted']))
- {
- if($formproc->ProcessForm())
- {
- $formproc->RedirectToURL("thank-you.php");
- }
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
- <head>
- <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
- <title>Contact us</title>
- <link rel="STYLESHEET" type="text/css" href="contact.css" />
- <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
- <script type='text/javascript' src='scripts/fg_captcha_validator.js'></script>
- </head>
- <body>
- <!-- Form Code Start -->
- <form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
- <fieldset >
- <legend>Contact us</legend>
- <input type='hidden' name='submitted' id='submitted' value='1'/>
- <input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
- <input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
- <div class='short_explanation'>* required fields</div>
- <div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
- <div class='container'>
- <label for='name' >Your Full Name*: </label><br/>
- <input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
- <span id='contactus_name_errorloc' class='error'></span>
- </div>
- <div class='container'>
- <label for='email' >Email Address*:</label><br/>
- <input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
- <span id='contactus_email_errorloc' class='error'></span>
- </div>
- <div class='container'>
- <label for='message' >Message:</label><br/>
- <span id='contactus_message_errorloc' class='error'></span>
- <textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
- </div>
- <div class='container'>
- <label for='photo' >Upload your photo:</label><br/>
- <input type="file" name='photo' id='photo' /><br/>
- <span id='contactus_photo_errorloc' class='error'></span>
- </div>
- <!--submit 在这里-->
- <div class='container'>
- <input type='submit' name='Submit' value='Submit' />
- </div>
- </fieldset>
- </form>
- <!-- client-side Form Validations:
- Uses the excellent form validation script from JavaScript-coder.com-->
- <script type='text/javascript'>
- // <![CDATA[
- var frmvalidator = new Validator("contactus");
- frmvalidator.EnableOnPageErrorDisplay();
- frmvalidator.EnableMsgsTogether();
- frmvalidator.addValidation("name","req","Please provide your name");
- frmvalidator.addValidation("email","req","Please provide your email address");
- frmvalidator.addValidation("email","email","Please provide a valid email address");
- frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");
- frmvalidator.addValidation("photo","file_extn=jpg;jpeg;gif;png;bmp","Upload images only. Supported file types are: jpg,gif,png,bmp");
- // ]]>
- </script>
- </body>
- </html>
复制代码
还有这个是有连接form的,从提交资料到email都有关系的,不懂有没有关系,不过也分享出来吧
- <?PHP
- /*
- Contact Form from HTML Form Guide
- This program is free software published under the
- terms of the GNU Lesser General Public License.
- This program is distributed in the hope that it will
- be useful - WITHOUT ANY WARRANTY; without even the
- implied warranty of MERCHANTABILITY or FITNESS FOR A
- PARTICULAR PURPOSE.
- [url=home.php?mod=space&uid=615991]@copyright[/url] html-form-guide.com 2010
- */
- require_once("class.phpmailer.php");
- /*
- Interface to Captcha handler
- */
- class FG_CaptchaHandler
- {
- function Validate() { return false;}
- function GetError(){ return '';}
- }
- /*
- FGContactForm is a general purpose contact form class
- It supports Captcha, HTML Emails, sending emails
- conditionally, File atachments and more.
- */
- class FGContactForm
- {
- var $receipients;
- var $errors;
- var $error_message;
- var $name;
- var $email;
- var $message;
- var $from_address;
- var $form_random_key;
- var $conditional_field;
- var $arr_conditional_receipients;
- var $fileupload_fields;
- var $captcha_handler;
- var $mailer;
- function FGContactForm()
- {
- $this->receipients = array();
- $this->errors = array();
- $this->form_random_key = 'HTgsjhartag';
- $this->conditional_field='';
- $this->arr_conditional_receipients=array();
- $this->fileupload_fields=array();
- $this->mailer = new PHPMailer();
- $this->mailer->CharSet = 'utf-8';
- }
- function EnableCaptcha($captcha_handler)
- {
- $this->captcha_handler = $captcha_handler;
- session_start();
- }
- function AddRecipient($email,$name="")
- {
- $this->mailer->AddAddress($email,$name);
- }
- function SetFromAddress($from)
- {
- $this->from_address = $from;
- }
- function SetFormRandomKey($key)
- {
- $this->form_random_key = $key;
- }
- function GetSpamTrapInputName()
- {
- return 'sp'.md5('KHGdnbvsgst'.$this->GetKey());
- }
- function SafeDisplay($value_name)
- {
- if(empty($_POST[$value_name]))
- {
- return'';
- }
- return htmlentities($_POST[$value_name]);
- }
- function GetFormIDInputName()
- {
- $rand = md5('TygshRt'.$this->GetKey());
- $rand = substr($rand,0,20);
- return 'id'.$rand;
- }
- function GetFormIDInputValue()
- {
- return md5('jhgahTsajhg'.$this->GetKey());
- }
- function SetConditionalField($field)
- {
- $this->conditional_field = $field;
- }
- function AddConditionalReceipent($value,$email)
- {
- $this->arr_conditional_receipients[$value] = $email;
- }
- function AddFileUploadField($file_field_name,$accepted_types,$max_size)
- {
- $this->fileupload_fields[] =
- array("name"=>$file_field_name,
- "file_types"=>$accepted_types,
- "maxsize"=>$max_size);
- }
- function ProcessForm()
- {
- if(!isset($_POST['submitted']))
- {
- return false;
- }
- if(!$this->Validate())
- {
- $this->error_message = implode('<br/>',$this->errors);
- return false;
- }
- $this->CollectData();
- $ret = $this->SendFormSubmission();
- return $ret;
- }
- function RedirectToURL($url)
- {
- header("Location: $url");
- exit;
- }
- function GetErrorMessage()
- {
- return $this->error_message;
- }
- function GetSelfScript()
- {
- return htmlentities($_SERVER['PHP_SELF']);
- }
- function GetName()
- {
- return $this->name;
- }
- function GetEmail()
- {
- return $this->email;
- }
- function GetMessage()
- {
- return htmlentities($this->message,ENT_QUOTES,"UTF-8");
- }
- /*-------- Private (Internal) Functions -------- */
- function SendFormSubmission()
- {
- $this->CollectConditionalReceipients();
- $this->mailer->CharSet = 'utf-8';
-
- $this->mailer->Subject = "Contact form submission from $this->name";
- $this->mailer->From = $this->GetFromAddress();
- $this->mailer->FromName = $this->name;
- $this->mailer->AddReplyTo($this->email);
- $message = $this->ComposeFormtoEmail();
- $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
- $this->mailer->AltBody = @html_entity_decode($textMsg,ENT_QUOTES,"UTF-8");
- $this->mailer->MsgHTML($message);
- $this->AttachFiles();
- if(!$this->mailer->Send())
- {
- $this->add_error("Failed sending email!");
- return false;
- }
- return true;
- }
- function CollectConditionalReceipients()
- {
- if(count($this->arr_conditional_receipients)>0 &&
- !empty($this->conditional_field) &&
- !empty($_POST[$this->conditional_field]))
- {
- foreach($this->arr_conditional_receipients as $condn => $rec)
- {
- if(strcasecmp($condn,$_POST[$this->conditional_field])==0 &&
- !empty($rec))
- {
- $this->AddRecipient($rec);
- }
- }
- }
- }
- /*
- Internal variables, that you donot want to appear in the email
- Add those variables in this array.
- */
- function IsInternalVariable($varname)
- {
- $arr_interanl_vars = array('scaptcha',
- 'submitted',
- $this->GetSpamTrapInputName(),
- $this->GetFormIDInputName()
- );
- if(in_array($varname,$arr_interanl_vars))
- {
- return true;
- }
- return false;
- }
- function FormSubmissionToMail()
- {
- $ret_str='';
- foreach($_POST as $key=>$value)
- {
- if(!$this->IsInternalVariable($key))
- {
- $value = htmlentities($value,ENT_QUOTES,"UTF-8");
- $value = nl2br($value);
- $key = ucfirst($key);
- $ret_str .= "<div class='label'>$key :</div><div class='value'>$value </div>\n";
- }
- }
- foreach($this->fileupload_fields as $upload_field)
- {
- $field_name = $upload_field["name"];
- if(!$this->IsFileUploaded($field_name))
- {
- continue;
- }
-
- $filename = basename($_FILES[$field_name]['name']);
- $ret_str .= "<div class='label'>File upload '$field_name' :</div><div class='value'>$filename </div>\n";
- }
- return $ret_str;
- }
- function ExtraInfoToMail()
- {
- $ret_str='';
- $ip = $_SERVER['REMOTE_ADDR'];
- $ret_str = "<div class='label'>IP address of the submitter:</div><div class='value'>$ip</div>\n";
- return $ret_str;
- }
- function GetMailStyle()
- {
- $retstr = "\n<style>".
- "body,.label,.value { font-family:Arial,Verdana; } ".
- ".label {font-weight:bold; margin-top:5px; font-size:1em; color:#333;} ".
- ".value {margin-bottom:15px;font-size:0.8em;padding-left:5px;} ".
- "</style>\n";
- return $retstr;
- }
- function GetHTMLHeaderPart()
- {
- $retstr = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n".
- '<html><head><title></title>'.
- '<meta http-equiv=Content-Type content="text/html; charset=utf-8">';
- $retstr .= $this->GetMailStyle();
- $retstr .= '</head><body>';
- return $retstr;
- }
- function GetHTMLFooterPart()
- {
- $retstr ='</body></html>';
- return $retstr ;
- }
- function ComposeFormtoEmail()
- {
- $header = $this->GetHTMLHeaderPart();
- $formsubmission = $this->FormSubmissionToMail();
- $extra_info = $this->ExtraInfoToMail();
- $footer = $this->GetHTMLFooterPart();
- $message = $header."Submission from 'contact us' form:<p>$formsubmission</p><hr/>$extra_info".$footer;
- return $message;
- }
- function AttachFiles()
- {
- foreach($this->fileupload_fields as $upld_field)
- {
- $field_name = $upld_field["name"];
- if(!$this->IsFileUploaded($field_name))
- {
- continue;
- }
-
- $filename =basename($_FILES[$field_name]['name']);
- $this->mailer->AddAttachment($_FILES[$field_name]["tmp_name"],$filename);
- }
- }
- function GetFromAddress()
- {
- if(!empty($this->from_address))
- {
- return $this->from_address;
- }
- $host = $_SERVER['SERVER_NAME'];
- $from ="nobody@$host";
- return $from;
- }
- function Validate()
- {
- $ret = true;
- //security validations
- if(empty($_POST[$this->GetFormIDInputName()]) ||
- $_POST[$this->GetFormIDInputName()] != $this->GetFormIDInputValue() )
- {
- //The proper error is not given intentionally
- $this->add_error("Automated submission prevention: case 1 failed");
- $ret = false;
- }
- //This is a hidden input field. Humans won't fill this field.
- if(!empty($_POST[$this->GetSpamTrapInputName()]) )
- {
- //The proper error is not given intentionally
- $this->add_error("Automated submission prevention: case 2 failed");
- $ret = false;
- }
- //name validations
- if(empty($_POST['name']))
- {
- $this->add_error("Please provide your name");
- $ret = false;
- }
- else
- if(strlen($_POST['name'])>50)
- {
- $this->add_error("Name is too big!");
- $ret = false;
- }
- //email validations
- if(empty($_POST['email']))
- {
- $this->add_error("Please provide your email address");
- $ret = false;
- }
- else
- if(strlen($_POST['email'])>50)
- {
- $this->add_error("Email address is too big!");
- $ret = false;
- }
- else
- if(!$this->validate_email($_POST['email']))
- {
- $this->add_error("Please provide a valid email address");
- $ret = false;
- }
- //message validaions
- if(strlen($_POST['message'])>2048)
- {
- $this->add_error("Message is too big!");
- $ret = false;
- }
- //captcha validaions
- if(isset($this->captcha_handler))
- {
- if(!$this->captcha_handler->Validate())
- {
- $this->add_error($this->captcha_handler->GetError());
- $ret = false;
- }
- }
- //file upload validations
- if(!empty($this->fileupload_fields))
- {
- if(!$this->ValidateFileUploads())
- {
- $ret = false;
- }
- }
- return $ret;
- }
- function ValidateFileType($field_name,$valid_filetypes)
- {
- $ret=true;
- $info = pathinfo($_FILES[$field_name]['name']);
- $extn = $info['extension'];
- $extn = strtolower($extn);
- $arr_valid_filetypes= explode(',',$valid_filetypes);
- if(!in_array($extn,$arr_valid_filetypes))
- {
- $this->add_error("Valid file types are: $valid_filetypes");
- $ret=false;
- }
- return $ret;
- }
- function ValidateFileSize($field_name,$max_size)
- {
- $size_of_uploaded_file =
- $_FILES[$field_name]["size"]/1024;//size in KBs
- if($size_of_uploaded_file > $max_size)
- {
- $this->add_error("The file is too big. File size should be less than $max_size KB");
- return false;
- }
- return true;
- }
- function IsFileUploaded($field_name)
- {
- if(empty($_FILES[$field_name]['name']))
- {
- return false;
- }
- if(!is_uploaded_file($_FILES[$field_name]['tmp_name']))
- {
- return false;
- }
- return true;
- }
- function ValidateFileUploads()
- {
- $ret=true;
- foreach($this->fileupload_fields as $upld_field)
- {
- $field_name = $upld_field["name"];
- $valid_filetypes = $upld_field["file_types"];
-
- if(!$this->IsFileUploaded($field_name))
- {
- continue;
- }
- if($_FILES[$field_name]["error"] != 0)
- {
- $this->add_error("Error in file upload; Error code:".$_FILES[$field_name]["error"]);
- $ret=false;
- }
- if(!empty($valid_filetypes) &&
- !$this->ValidateFileType($field_name,$valid_filetypes))
- {
- $ret=false;
- }
- if(!empty($upld_field["maxsize"]) &&
- $upld_field["maxsize"]>0)
- {
- if(!$this->ValidateFileSize($field_name,$upld_field["maxsize"]))
- {
- $ret=false;
- }
- }
- }
- return $ret;
- }
- function StripSlashes($str)
- {
- if(get_magic_quotes_gpc())
- {
- $str = stripslashes($str);
- }
- return $str;
- }
- /*
- Sanitize() function removes any potential threat from the
- data submitted. Prevents email injections or any other hacker attempts.
- if $remove_nl is true, newline chracters are removed from the input.
- */
- function Sanitize($str,$remove_nl=true)
- {
- $str = $this->StripSlashes($str);
- if($remove_nl)
- {
- $injections = array('/(\n+)/i',
- '/(\r+)/i',
- '/(\t+)/i',
- '/(%0A+)/i',
- '/(%0D+)/i',
- '/(%08+)/i',
- '/(%09+)/i'
- );
- $str = preg_replace($injections,'',$str);
- }
- return $str;
- }
- /*Collects clean data from the $_POST array and keeps in internal variables.*/
- function CollectData()
- {
- $this->name = $this->Sanitize($_POST['name']);
- $this->email = $this->Sanitize($_POST['email']);
- /*newline is OK in the message.*/
- $this->message = $this->StripSlashes($_POST['message']);
- }
- function add_error($error)
- {
- array_push($this->errors,$error);
- }
- function validate_email($email)
- {
- return eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}[ DISCUZ_CODE_1 ]quot;, $email);
- }
- function GetKey()
- {
- return $this->form_random_key.$_SERVER['SERVER_NAME'].$_SERVER['REMOTE_ADDR'];
- }
- }
- ?>
复制代码
|
|
|
|
|
|
|
|
发表于 27-9-2015 02:08 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 27-9-2015 02:54 PM
|
显示全部楼层
阿弥陀佛 _/\_ 学佛和工作也是可以在一起的
不过我的工作是杂杂的,没有读过,都是自学,
看了你的回复,感觉有点深,我再消化消化下,
不然你帮我加上去后,然后我在参考是哪里的问题,
因为有些代码我不熟,如果你肯帮我写上去后,然后我再参考那会更好
|
|
|
|
|
|
|
|

楼主 |
发表于 27-9-2015 02:57 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 27-9-2015 03:00 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 27-9-2015 03:09 PM
|
显示全部楼层
还是不可以,是不是submit罢了我排位放错了?
|
|
|
|
|
|
|
|

楼主 |
发表于 27-9-2015 03:18 PM
|
显示全部楼层
第4楼的我不懂要怎样实现在form那里,老实说,我不会自己写的,我只会修改和加一些基本的美观,和基本的html,太深我真的不会
所以希望你们不要骂我,这个form我也是拿来当做学习学习
|
|
|
|
|
|
|
|
发表于 27-9-2015 03:19 PM
|
显示全部楼层
暈了…… 
大大試試看這個先~
可以才再 mod 吧~
第一個 form 45 行那裏用:
- <form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' onsubmit="return confirm('代入符合所要求 confirmation box 之内容');" enctype="multipart/form-data" accept-charset='UTF-8'>
复制代码
如果可以 run,
蛋速想要比較複雜 look 的
就第一個 form 45 行那裏用:
- <form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' onsubmit="onSubmit(event) enctype="multipart/form-data" accept-charset='UTF-8'>
复制代码
然後 85 行之後加入
- <script>
- function onSubmit(e) {
- if (!confirm("代入符合所要求 confirmation box 之内容")) {
- e.preventDefault(); //阻止事件进行
- }
- }
- </script>
复制代码 |
|
|
|
|
|
|
|
发表于 27-9-2015 03:22 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 27-9-2015 03:47 PM
|
显示全部楼层
你回复的字要我用另外一种方式来阅读才明白 
上面的方法,我现在试试,有不明白再问问
|
|
|
|
|
|
|
|
发表于 27-9-2015 03:52 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 27-9-2015 04:05 PM
|
显示全部楼层
- <?PHP
- /*
- Contact Form from HTML Form Guide
- This program is free software published under the
- terms of the GNU Lesser General Public License.
- See this page for more info:
- http://www.html-form-guide.com/contact-form/contact-form-attachment.html
- */
- require_once("./include/fgcontactform.php");
- $formproc = new FGContactForm();
- //1. Add your email address here.
- //You can add more than one receipients.
- $formproc->AddRecipient('tests@html-form-guide.com'); //<<---Put your email address here
- //2. For better security. Get a random tring from this link: http://tinyurl.com/randstr
- // and put it here
- $formproc->SetFormRandomKey('HG9hPBpn9Bn26yg');
- $formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024);
- if(isset($_POST['submitted']))
- {
- if($formproc->ProcessForm())
- {
- $formproc->RedirectToURL("thank-you.php");
- }
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
- <head>
- <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
- <title>Contact us</title>
- <link rel="STYLESHEET" type="text/css" href="contact.css" />
- <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
- <script type='text/javascript' src='scripts/fg_captcha_validator.js'></script>
- </head>
- <body>
- <!-- Form Code Start -->
- <form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' onsubmit="return confirm('代入符合所要求 confirmation box 之内容');" enctype="multipart/form-data" accept-charset='UTF-8'>
- <fieldset >
- <legend>Contact us</legend>
- <input type='hidden' name='submitted' id='submitted' value='1'/>
- <input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
- <input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
- <div class='short_explanation'>* required fields</div>
- <div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
- <div class='container'>
- <label for='name' >Your Full Name*: </label><br/>
- <input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
- <span id='contactus_name_errorloc' class='error'></span>
- </div>
- <div class='container'>
- <label for='email' >Email Address*:</label><br/>
- <input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
- <span id='contactus_email_errorloc' class='error'></span>
- </div>
- <div class='container'>
- <label for='message' >Message:</label><br/>
- <span id='contactus_message_errorloc' class='error'></span>
- <textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
- </div>
- <div class='container'>
- <label for='photo' >Upload your photo:</label><br/>
- <input type="file" name='photo' id='photo' /><br/>
- <span id='contactus_photo_errorloc' class='error'></span>
- </div>
- <div class='container'>
- <input type='submit' name='Submit' value='Submit' />
- </div>
- </fieldset>
- </form>
- <script>
- function onSubmit(e) {
- if (!confirm("代入符合所要求 confirmation box 之内容")) {
- e.preventDefault(); //阻止事件进行
- }
- }
- </script>
- <!-- client-side Form Validations:
- Uses the excellent form validation script from JavaScript-coder.com-->
- <script type='text/javascript'>
- // <![CDATA[
- var frmvalidator = new Validator("contactus");
- frmvalidator.EnableOnPageErrorDisplay();
- frmvalidator.EnableMsgsTogether();
- frmvalidator.addValidation("name","req","Please provide your name");
- frmvalidator.addValidation("email","req","Please provide your email address");
- frmvalidator.addValidation("email","email","Please provide a valid email address");
- frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");
- frmvalidator.addValidation("photo","file_extn=jpg;jpeg;gif;png;bmp","Upload images only. Supported file types are: jpg,gif,png,bmp");
- // ]]>
- </script>
- </body>
- </html>
复制代码 照你方式了,还是不行,是不是哪里有错??
还是你帮我直接加,然后我自己在用beyond compare哪里出错就行了。
|
|
|
|
|
|
|
|
发表于 27-9-2015 04:16 PM
|
显示全部楼层
大大…… 二選一~ 二選一啊~ 表那麽貪心好不好 
速不速辣過一比二多滴廣告太洗腦鳥 
- <?PHP
- /*
- Contact Form from HTML Form Guide
- This program is free software published under the
- terms of the GNU Lesser General Public License.
- See this page for more info:
- http://www.html-form-guide.com/contact-form/contact-form-attachment.html
- */
- require_once("./include/fgcontactform.php");
- $formproc = new FGContactForm();
- //1. Add your email address here.
- //You can add more than one receipients.
- $formproc->AddRecipient('tests@html-form-guide.com'); //<<---Put your email address here
- //2. For better security. Get a random tring from this link: http://tinyurl.com/randstr
- // and put it here
- $formproc->SetFormRandomKey('HG9hPBpn9Bn26yg');
- $formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024);
- if(isset($_POST['submitted']))
- {
- if($formproc->ProcessForm())
- {
- $formproc->RedirectToURL("thank-you.php");
- }
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
- <head>
- <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
- <title>Contact us</title>
- <link rel="STYLESHEET" type="text/css" href="contact.css" />
- <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
- <script type='text/javascript' src='scripts/fg_captcha_validator.js'></script>
- </head>
- <body>
- <!-- Form Code Start -->
- <form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' onsubmit="return confirm('confirm submit?');" enctype="multipart/form-data" accept-charset='UTF-8'>
- <fieldset >
- <legend>Contact us</legend>
- <input type='hidden' name='submitted' id='submitted' value='1'/>
- <input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
- <input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
- <div class='short_explanation'>* required fields</div>
- <div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
- <div class='container'>
- <label for='name' >Your Full Name*: </label><br/>
- <input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
- <span id='contactus_name_errorloc' class='error'></span>
- </div>
- <div class='container'>
- <label for='email' >Email Address*:</label><br/>
- <input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
- <span id='contactus_email_errorloc' class='error'></span>
- </div>
- <div class='container'>
- <label for='message' >Message:</label><br/>
- <span id='contactus_message_errorloc' class='error'></span>
- <textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
- </div>
- <div class='container'>
- <label for='photo' >Upload your photo:</label><br/>
- <input type="file" name='photo' id='photo' /><br/>
- <span id='contactus_photo_errorloc' class='error'></span>
- </div>
- <div class='container'>
- <input type='submit' name='Submit' value='Submit' />
- </div>
- </fieldset>
- </form>
- <!-- client-side Form Validations:
- Uses the excellent form validation script from JavaScript-coder.com-->
- <script type='text/javascript'>
- // <![CDATA[
- var frmvalidator = new Validator("contactus");
- frmvalidator.EnableOnPageErrorDisplay();
- frmvalidator.EnableMsgsTogether();
- frmvalidator.addValidation("name","req","Please provide your name");
- frmvalidator.addValidation("email","req","Please provide your email address");
- frmvalidator.addValidation("email","email","Please provide a valid email address");
- frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");
- frmvalidator.addValidation("photo","file_extn=jpg;jpeg;gif;png;bmp","Upload images only. Supported file types are: jpg,gif,png,bmp");
- // ]]>
- </script>
- </body>
- </html>
复制代码
偶敗倒…… 
大大繞了偶啊…… |
|
|
|
|
|
|
|

楼主 |
发表于 27-9-2015 04:32 PM
|
显示全部楼层
我试了你的code..我整份copy了,还是不可以
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|