I have designed a contact form and I need to receive mail from the "Contact Us" page, on a specific email ID.
This my form:
contact.html
<form action="contactservlet" method="post">
<h4>Get in <i>Touch</i></h4>
<input type="text" id="name" name="name" placeholder="NAME" class="input-style" />
<input type="email" id="emailid" name="emailid" placeholder="EMAIl" oninput="sendRequest('GET','Checkemailid',1)" required="required" class="input-style" />
<input type="text" id="mobno" name="mobno" placeholder="Enter Mobile No." required="required" class="input-style"/>
<textarea type="text" id="message" name="message" placeholder="MESSAGE" required="required" class="input-style"></textarea>
<div class="contact-btn">
<a title="" href="#"><input type="submit" id="submit" value="Submit"/></a>
</div>
</form>
I don't know how to write contactservlet.java.
UPDATED
Try this,
ContactUs.html
<form action="ContactServlet" method="post">
<h4>Get in <i>Touch</i></h4>
<input type="text" id="name" name="name" placeholder="Name" />
<input type="email" id="emailId" name="emailId" placeholder="Email" />
<input type="text" id="mobileNo" name="mobileNo" placeholder="Enter Mobile No." />
<textarea type="text" id="message" name="message" placeholder="Message"></textarea>
<input type="submit" id="submit" value="Submit"/>
</form>
For sending mails we used JavaMail API. Download and Documentation.
ContactServlet.java -> doPost()
//This data will be added to your Database using DAO Layer....
String name=request.getParameter("name");
String emailId=request.getParameter("emailId");
Long mobno=Long.parseLong(request.getParameter("mobileNo"));
String message= request.getParameter("message");
//Call Some function that do database storage.....
//Sending Mail Through Gmail SMTP
//Separate this code at DAO/Service Layer - - -
final String gmailUsername = "somethin#gmail.com";
final String gmailPassword = "somethin#123";
try{
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
#Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(gmailUsername, gmailPassword);
}
});
Message mailMessage = new MimeMessage(session);
mailMessage.setFrom(new InternetAddress("somethin#gmail.com"));
mailMessage.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(emailId));
mailMessage.setSubject("Type Subject : ");
mailMessage.setText("Type LONGGGG Message Here......");
Transport.send(mailMessage);
} catch(MessagingException e){
e.printStackTrace();
}
Related
Here is the problem I have:
When validating my form I would like to :
1- Send the form information to a Webhook (to process the information) I would like it to be invisible for the user
2- Redirect the user to a confirmation page (or display a confirmation message on the form)
Here is my current form that only sends the info to the webhook:
<form method="post" action="https://hooks.zapier.com/hooks/catch/12195186/bzjhk97/">
<input id="prenom" type="text" name="first_name" placeholder="Votre prénom" required="required" />
<input id="email" type="email" name="email" placeholder="Votre adresse e-mail" required="required" />
<button id="submit" type="submit" class="btn">RECEVOIR LE KIT COMPLET</button>
I don't know if it's adjustable with Javascript or just HTML...
Thanks for your help :)
You can change your button type to "button" and then add a handler to that button to POST the data. In the example below I modified your code to do that and use fetch to POST the data to the endpoint.
Inside the ".then" part is the callback (this does not get execited until you receive the response from the fetch). This is where you would display the dialog to the user or redirect them to another page.
<form method="post" action="https://hooks.zapier.com/hooks/catch/12195186/bzjhk97/">
<input id="prenom" type="text" name="first_name" id="first_name" placeholder="Votre prénom" required="required" />
<input id="email" type="email" name="email" id="email" placeholder="Votre adresse e-mail" required="required" />
<button id="submit" type="button" class="btn" id="btn">RECEVOIR LE KIT COMPLET</button>
</form>
<script>
const getButton = document.getElementById('btn');
const getFirstName = document.getElementById('first_name');
const getEmail = document.getElementById('email');
fetch('https://hooks.zapier.com/hooks/catch/12195186/bzjhk97/', {
method: 'POST',
body: new URLSearchParams({
first_name: getFirstName.value,
email: email.value
})
})
.then(response => {
// Do stuff with the response
});
I am trying to enter data inside database table via form. I have created an instance of Model and accessed the columns of that table and assigned the input names of form but when I enter data an submit it says Attempt to read property "name" on array. Can anyone guide me if there is anything wrong.
Code of Controller where im inserting datas to database
class UserController extends Controller
{
function registerUser(Request $req)
{
$data = $req->input();
$user_model = new User;
$user_model->fullname = $data->name;
$user_model->mobile = $data->mobile;
$user_model->email = $data->email;
$user_model->password = $data->password;
$user_model->save();
return "registered successfully";
}
}
Code of Form
<div class="register-form">
<h4>Sign Up</h4>
<form method="post" action="register">
#csrf
<input type="text" name="name" placeholder="Full Name" size="40">
<br>
<input type="tel" name="mobile" placeholder="Mobile number" size="40">
<br>
<input type="email" name="email" placeholder="Email" size="40">
<br>
<input type="password" name="password" placeholder="Password" size="40">
<br>
<input id="submit_btn" type="submit" placeholder="Sign Up" size="40">
<hr>
<p>Already, have an account <span href="#" id="sign-in-link">Log In</span></p>
</form>
</div>
function registerUser(Request $req)
{
$user_model = new User;
$user_model->fullname = $req->name;
$user_model->mobile = $req->mobile;
$user_model->email = $req->email;
$user_model->password = bcrypt($req->password); //laravel hashed password
$user_model->save();
return "registered successfully";
}
$req->input is an array. Access it like so.
$user_model->fullname = $data['name'];
$user_model->mobile = $data['mobile'];
$user_model->email = $data['email'];
$user_model->password = $data['password'];
I am trying to specify a dynamic url in the actions properties of form.
The url will be dependant on what the user enters in the textbox. For example, if the user enters "Fred" as firstname and 1234 as courseId, then the url should be "/users/Fred/course/1234"
This is what I have so far but it is not reading the firstname and courseId.
<form action="/users/{{firstname}}/course/{{courseId}}" method="POST">
<input type="text" placeholder="firstname" name="firstname">
<input type="email" placeholder="email" name="email">
<input type="text" placeholder="courseId" name="courseId">
<input type="submit" value="Submit">
</form>
No php and ajax can be used.
You need javascript to do this
const template = (firstname, courseId) => `/users/${firstname}/course/${courseId}`;
document.getElementById('myForm').addEventListener('submit', function(s) {
s.preventDefault();
this.action = template(this.elements["firstname"].value, this.elements["courseId"].value);
this.submit();
});
<form action="placeholder" method="POST" id="myForm">
<input type="text" placeholder="firstname" name="firstname">
<input type="email" placeholder="email" name="email">
<input type="text" placeholder="courseId" name="courseId">
<input type="submit" value="Submit">
</form>
I am trying to make a program log into a website using WebRequest and then copy the html page that comes after login into a string.
let returnHTML (url : string) =
let request = System.Net.WebRequest.Create(System.Uri(url))
let response = request.GetResponse()
let stream = response.GetResponseStream()
let reader = new System.IO.StreamReader(stream)
let webstring = reader.ReadToEnd ()
webstring
printfn "%A" (returnHTML "myURL")
The above code copies the login page into a string because i have not implemented some sort of login session yet. This is where i hope some of you can break it down for dummies.
The form that needs login into looks like this :
<form name="loginform" id="loginform" action="https://aamanasdasdad" method="post">
<p>
<label for="user_login">Brugernavn eller e-mailadresse<br />
<input type="text" name="log" id="user_login" class="input" value="" size="20" /></label>
</p>
<p>
<label for="user_pass">Password<br />
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
</p>
<p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> Husk mig</label></p>
<p class="submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log ind" />
<input type="hidden" name="redirect_to" value="https://aamansasns.asdasddk/wp-admin/admiadasdad" />
<input type="hidden" name="testcookie" value="1" />
</p>
Can someone please guide me on how to reach the last step?
I need to make a JqueryMobile app for college work,
i have that form -
<form name="local_storage_form" method="post" action="#" data-ajax="false" autocomplete="on" data- theme="e" style="padding: 10px;" onsubmit="save_data()">
<label for="id">identity card number</label><input type="text" name="id" id="id" placeholder="identity card number..." data-theme="e" required class="localStore">
<label for="hphone">Home Phone Number</label><input type="tel" name="hphone" id="hphone" placeholder="Home Phone Number..." data-theme="e" class="localStore">
<label for="mphone">Mobile Phone Number</label><input type="text" name="mphone" id="mphone" placeholder="Mobile Phone Number..." data-theme="e" required class="localStore" oninvalid="setCustomValidity('Invaild Phone Number (05********)')">
<label for="bdate">Birth Date</label><input type="date" name="bdate" placeholder="Birth Date..." id="bdate" data-theme="e" required class="localStore">
<label for="email">Email Address</label><input type="email" name="email" id="email" autocomplete="off" placeholder="Email Address..." data-theme="e" required class="localStore">
<button type="button" value="Save" id="Save" data-theme="a">Submit</button>
</form>
i need to store all the details on localstorage and get them after,
how can i do it when i click on the submit button?
btw,it's an offline website so when i click submit it gives me an error.
Have a look into the Jquery API documentation.
$('#local_storage_form').submit(function(e) {
e.preventDefault(); // prevent the form from attempting to send to the web server
var $inputs = $('#local_storage_form :input');
var values = {};
$inputs.each(function() {
values[this.name] = $(this).val();
});
localStorage.setItem('testForm', JSON.stringify(values));
});