unable to post to a php script - javascript

I am currently deploying a contact form to a website via twitter bootstrap where the form posts to a php script that sends an email to an administrator. The problem is that the form does not submit if the file js/plugins/validator/jquery.form-validator.min.js is used for validation
I can get the form to function and submit an email successfully when I remove the validation file below:
js/plugins/validator/jquery.form-validator.min.js
from the script section at the bottom of the page, but this removes all the validation on the form
<form method="post" action="sendmail.php" class="input-group input-group-lg" id="subscribeForm" >
<input type="text class="form-control" placeholder="Name" id="name" name="name" />
<input type="text" name="company" class="form-control" placeholder="company" /><br />
<input type="text" name="phone" class="form-control" placeholder="phone" /><br />
<input type="email" class="form-control" placeholder="email" id="sEmail" name="email">
<span class="input-group-btn">
<input type="submit" button class="btn bg-primary">Invite Me!</button>
</span></form><!-- /input-group -->
And the content of the sendmail.php
<?php
$name = $_REQUEST['name'];
$company = $_REQUEST['company'];
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'];
$emess = "Name: ".$name."\n";
$emess.= "Company: ".$company."\n";
$emess.= "Email : ".$email."\n";
$emess.= "Phone number: ".$phone."\n";
mail( "send-to-email", "Information Request",
$emess, "From: $email" );
header( "Location: http://www.google.com" );?>

In your code you have
<input type="text class="form-control" placeholder="Name" id="name" name="name" />
^ right there
which you are missing a quote " after text. Throw that in and it should work.
Another thing to note on the php side, use $name = $_POST['name']; instead since you are sending a form via post and $_REQUEST, by default, contains the contents of $_GET, $_POST and $_COOKIE.
Edit: As Fred pointed out on the input button it should be
<input type="submit" class="btn bg-primary" value="Invite Me!" />

Changed the input submit tag
<form method="post" action="sendmail.php" class="input-group input-group-lg" id="subscribeForm" >
<input type="text" class="form-control" placeholder="Name" id="name" name="name" />
<input type="text" name="company" class="form-control" placeholder="company" /><br />
<input type="text" name="phone" class="form-control" placeholder="phone" /><br />
<input type="email" class="form-control" placeholder="email" id="sEmail" name="email">
<span class="input-group-btn">
<input type="submit" value="Invite Me!" />
</span></form>

Related

Automatic filling of identical registration fields at the same time

I need to help. I have a next form
<form action="" method="POST">
<input type="email" name="email">
<input type="email" name="email-repeat">
<input type="password" name="password">
<input type="password" name="password-repeat">
<input type="submit" value="">
</form>
and I want when I reload to page, that browser to autocomplete all fields from saved data in the browser(email and password) twice password and twice email. I tried a few combinations with attribute of autocomplete, but nothing.
You should add autocomplete="off" to the inputs that you don't want to be filled automatically.
<input autocomplete="off" type="email" name="email">
<input autocomplete="off" type="email" name="email-repeat">
<input autocomplete="off" type="password" name="password">
<input autocomplete="off" type="password" name="password-repeat">
<input type="submit" value="">
You can find details in MDN

how to display a response message on html after post request in nodejs

i wanted to display a message in html page after submiting the data, wether it is correct or not on the same html page, till now i can only do is show the message on new page.
below is the node code
app.post('/login',(req,res)=>{
try{
console.log(req.body)
if(req.body.yourname!='mohit')
res.send('Content-Type' )
else
res.send('thankyou for submission')
}catch(error){
res.send()
}
})
app.listen(port,()=>{
console.log('server started to'+port);
})
Below is the html code
<div class="container">
<form id="contact" action="/login" method="post">
<h3>Contact Form</h3>
<fieldset>
<input name="yourName" placeholder="Your name" type="text" tabindex="1" required autofocus>
</fieldset>
<fieldset>
<input name="Email" placeholder="Your Email Address" type="email" tabindex="2" required>
</fieldset>
<fieldset>
<input name="Phone" placeholder="Your Phone Number (optional)" type="tel" tabindex="3" required>
</fieldset>
<fieldset>
<input name="site" placeholder="Your Web Site (optional)" type="url" tabindex="4">
</fieldset>
<fieldset>
<textarea name="Message" placeholder="Type your message here...." tabindex="5"></textarea>
</fieldset>
<fieldset>
<button name="submit" type="submit" id="contact-submit">Submit</button>
</fieldset>
</form>
help would be really appricated?

Reset $_POST values after submition

Basically, I'm trying to do is to reset all the form values after submission. I've tried every post but not got success. Please tell me the way of resetting values after submission so that after refreshing the page the form doesn't submit again. Thank you Here is my piece of code. I've tried headers but it is giving me errors so tell me another way of resetting the submit post after submission.
<form name="myForm" id="myForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" role="form">
<div class="form-group">
<label>Name</label>
<span class="Name_input"> </span>
<input name="Name" id="Name" type="text" class="form-control" required placeholder="Your name" />
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Email</label>
<span class="Email_input"> </span>
<input name="Email" id="Email" type="text" class="form-control" required placeholder="Email address" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Phone</label>
<input name="Phone" id="Phone" type="text" class="form-control" placeholder="Phone number" />
</div>
</div>
</div>
<div class="form-group">
<label>Subject</label>
<span class="Subject_input"> </span>
<input name="Subject" id="Subject" type="text" class="form-control" required placeholder="Subject" />
</div>
<div class="form-group">
<label>Message</label>
<textarea class="form-control" name="message" id="message" placeholder="Write you message here..." style="height:100px;"></textarea>
</div>
<input type="Submit" name="Submit" value="Send message" class="btn btn-two"/><p><br /></p>
</form>
if(isset($_POST['Submit']))
{
$User_Name=$_POST['Name'];
$User_Email=$_POST['Email'];
if(isset($_POST['Phone']))
$User_PhoneNumber=$_POST['Phone'];
else
$User_PhoneNumber="";
$Feedback_Subject=$_POST['Subject'];
$Feedback_Message=$_POST['message'];
$Inserted=mysqli_query($con, "Insert into feedback (Name , Email, Phone_Number, Subject, Message )
VALUES('" . $User_Name . "', '" .$User_Email . "', '" . $User_PhoneNumber. "', '" . $Feedback_Subject . "','" . $Feedback_Message . "')");
}
Your form should not resubmit just because you refresh the page. However, I just using header(), to redirect to a fresh page, even if the same.
So, straight after the sql query:
header("Location: page.php");
and replace page with which ever page it is.
also, put
<?php ob_start(); ?>
at the very top (before html) of your script to prevent error: Cannot modify header information - headers already sent
...and for your other question:
$(window).bind("pageshow", function() {
$("#formvalue1,#formvalue2,#formvalue3").val('');
});
this will get triggered when the page is shown, even if not reloaded.

Jquery validate multiple inputs with email

I have a form where i ask the user to input email addresses for an automated email to be sent. I have set both the email inputs to be required and to check for valid email, but it seems to work only for the first one. What am I doing wrong here?
<form class="validate" method="post" id="formLoc">
<div data-role="fieldcontain">
<label for="email-from">from</label>
<input type="text" class="required email" id="email-from" placeholder="from" />
</div>
<div data-role="fieldcontain">
<label for="email-to">to</label>
<input type="text" id="email-to" class="required email" placeholder="to" />
</div>
<div data-role="fieldcontain">
<label for="email-message">message</label>
<textarea id="email-message" cols="100" rows="40"></textarea>
</div>
<div class="email-sent">
<h4></h4>
</div>
<div class="SendEmailButton">
<button type="submit" data-role="button" data-icon="forward" data-inline="true"
data-mini="true" data-theme="c">send</button>
</div>
</form>
Here's a fiddle with the problem : http://jsfiddle.net/bobby5193/8dHg9/544/
Add the name attribute to both input fields.
<input type="text" name="email-from" class="required email" id="email-from" placeholder="from" />
<input type="text" name="email-to" id="email-to" class="required email" placeholder="to" />
<textarea name="email-message" id="email-message" cols="100" rows="40" class="required"></textarea>
Here is a jsFiddle
Update
Here is an updated jsFiddle which has validation on the textarea. I added the name attribute and class="required" to it.
If you want get more than one text box to insert Email like
<ul>
<li>
<input id="emailcheck" type="text" placeholder="Email" name="ToEmails[0]" required />
<input id="emailcheck" type="text" placeholder="Email" name="ToEmails[1]" required />
<input id="emailcheck" type="text" placeholder="Email" name="ToEmails[2]" required />
</li>
</ul>
Now we will get all email address from text box.
var email = $('input[name^=ToEmails]');
console.log(email);

How to validate an HTML form?

I have an HTML form and a button which when the user clicks will check whether or not the form is filled. The details for billing address is input from database using php
<button id="btnConfirm" type="submit" onclick="validate()"style="float: right" value="Confirm Payment" >Confirm Payment</button>
<form id="au" name="paymentform" method="post" action="" >
<fieldset class="billing">
<legend>Billing Details</legend>
<br />
<label class="reglabel" for="fname">First Name:</label>
<input id="fname" name="billingfname" required="" type="text" value="<?php echo $fname ?>" /><br />
<label class="reglabel" for="lname">Last Name:</label>
<input id="lname" name="billinglname" required="" type="text" value="<?php echo $lname ?>" /><br />
<label class="reglabel" for="address">Address:</label>
<input id="address" name="billingaddress" required="" type="text" value="<?php echo $address ?>" /><br />
<label class="reglabel" for="town">Town:</label>
<input id="town" name="billingtown" required="" type="text" value="<?php echo $town ?>" /><br />
<label class="reglabel" for="postcode">Post Code:</label>
<input id="postcode" name="billingpostcode" required="" type="text" value="<?php echo $postcode ?>" /><br />
<label class="reglabel" for="phone">Phone:</label>
<input id="phone" name="billingphone" required="" type="text" value="<?php echo $phone ?>" /><br />
<label id="EmailLabel" class="reglabel" for="email">E-mail:</label>
<input id="email" name="billingemail" required="" type="email" value="<?php echo $email ?>" /><br />
</fieldset>
<fieldset class="shipping">
<legend>Shipping Details</legend>
<br />
<input name="shippingsame" onclick="fillShipping(this.form)" type="checkbox">Check
this box if billing address and shipping address are the same <br />
<label class="reglabel" for="fname">First Name:</label>
<input id="fname" name="shippingfname" placeholder="Required" required="" type="text" /><br />
<label class="reglabel" for="lname">Last Name:</label>
<input id="lname" name="shippinglname" placeholder="Required" required="" type="text" /><br />
<label class="reglabel" for="address">Address:</label>
<input id="address" name="shippingaddress" placeholder="Required" required="" type="text" /><br />
<label class="reglabel" for="town">Town:</label>
<input id="town" name="shippingtown" placeholder="Required" required="" type="text" /><br />
<label class="reglabel" for="postcode">Post Code:</label>
<input id="postcode" name="shippingpostcode" placeholder="Required" required="" type="text" /><br />
<label class="reglabel" for="phone">Phone:</label>
<input id="phone" name="shippingphone" placeholder="Required" required="" type="text" /><br />
<label id="EmailLabel" class="reglabel" for="email">E-mail:</label>
<input id="email" name="shippingemail" placeholder="Required" required="" type="email" /><br />
</fieldset>
</form>
This is the code which Im trying to check whether or not he field is empty, but it doesnt seem to work. It alerts undefined
function validate()
{
var firstname = document.getElementsByName("shippingfname").value;
if (firstname == "")
{
alert('empty');
}
else
{
alert(firstname);
}
}
the function document.getElementsByName returns an array, so you should try this:
function validate()
{
var firstname = document.getElementsByName("shippingfname")[0].value;
if (firstname == "")
{
alert('empty');
}
else
{
alert(firstname);
}
}
Or you can use jquery validation plugin easily. ıt is great for client side validations http://docs.jquery.com/Plugins/validation
getElementsByName() returns an array. Not an individual element. In your example you will want to use the ID attribute to access individual elements.
<input name="shippingsame" id="shippingsame" onclick="fillShipping(this.form)" type="checkbox">
function validate()
{
var firstname = document.getElementByID("shippingfname").value;
if (firstname == "")
{
alert('empty');
}
else
{
alert(firstname);
}
}

Categories