in Education by
I have Html website. There is newsletter signup form in the html. It is processed by php script file for sending the email. After the form submission I want it back to the original page and also an alert message for "Thank you for newsletter signup" HTML : Javascript Validation : function ValidateForm(Form) { if (Form.stremail.value == "") { alert("Please enter \"Email\" "); Form.stremail.focus(); return (false); } if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Form.stremail.value)) == false) { alert("Invalid E-mail Address! Please re-enter."); Form.stremail.focus(); return (false); } return (true); } PHP Script : $stremail = $_POST["stremail"]; $to = "[email protected]"; $from = $stremail; $headers = "Content-type: text/html; charset=iso-8859-1\r\n"; $headers. = "From: \"$from\" <$from>\r\nReply-To: \"$from\" <$from>\r\nX-Mailer: PHP/".phpversion(); $headers. = "BCC: [email protected],[email protected]". "\r\n"; //for testing purpose $subject = "The Brandt Group Newsletter Signup"; $message = "Dear Administrator,\r\n\n"; $message = $message. "The following information was submitted to the website:

"; $message = $message. "Email Address : ".$stremail. "

"; mail($to, $subject, $message, $headers); header("Location: {$_SERVER[" HTTP_REFERER "]}"); $message2 = "Thank you for newsletter signup"; echo "alert('Thank you for newsletter signup');"; Any help ? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If you are using Jquery you can do like this: HTML side The form action and onsubmit attributs have been removed A class has been added on stremail input Javascript $(function(){ var form = $('form '); form.submit(function(e) { e.preventDefault(); if(ValidateForm(Form)) { var data = { 'stremail' : $('.stremail').val() } $.post("scripts/contact.php", data, function(response) { if(response.success) { alert(response.success); } else { // YOUR LOGIC WHEN ERROR OCCURED } }); } }); function ValidateForm(Form) { if (Form.stremail.value == "") { alert("Please enter \"Email\" "); Form.stremail.focus(); return(false); } if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Form.stremail.value)) == false) { alert("Invalid E-mail Address! Please re-enter."); Form.stremail.focus(); return (false); } return(true); } }); PHP Side Verify $_POST data and return response by type <?php $response = []; if(isset($_POST["stremail"]) && !empty($_POST["stremail"])) { $stremail = $_POST["stremail"]; $to="[email protected]"; $from = $stremail; $headers = "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .="From: \"$from\" <$from>\r\nReply-To: \"$from\" <$from>\r\nX-Mailer: PHP/".phpversion(); $headers .="BCC: [email protected],[email protected]" . "\r\n";//for testing purpose $subject = "The Brandt Group Newsletter Signup"; $message = "Dear Administrator,\r\n\n"; $message = $message ."The following information was submitted to the website:

"; $message = $message ."Email Address : ".$stremail."

"; mail($to,$subject,$message,$headers); $response['success'] = "Thank you for newsletter signup"; } else { $response['error'] = "YOUR_ERROR_MESSAGE"; } return $response; ?>

Related questions

0 votes
    I have Html website. There is newsletter signup form in the html. It is processed by php script file ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I have Html website. There is newsletter signup form in the html. It is processed by php script file ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm making a simple star rating feature in PHP to my site and my general question is, do cookies ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    I'm making a simple star rating feature in PHP to my site and my general question is, do cookies ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I'm making a simple star rating feature in PHP to my site and my general question is, do cookies ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I want to make a table to be able to help me make price comparisons. Explanations: In my table I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    How can you cancel a form submission through client script?...
asked May 25, 2021 in Technology by JackTerrance
0 votes
    I have a php file and it contains a textfiled and submit button and a div and below is code Page1 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have a php file and it contains a textfiled and submit button and a div and below is code Page1 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have one script and many websites, because they are on the same server how can I execute same ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have one script and many websites, because they are on the same server how can I execute same ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Friends, I have a contact us/Inquiry form in my website. I want to generate a lead in Sales force CRM on ... any link for API. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
...