Contact form with Bootstrap + Php not working - php

I am a beginner and I am trying to use this tutoriel http://untame.net/2013/05/how-to-build-a-modal-contact-form-in-twitter-bootstrap-with-php-ajax for creating my contact form. Email not sending ! Do you have an idea, why ? Thanks for your help !
After clicking on Send I have this on adresse web : http://viktorius.fr/?question=&email=&save=contact
Here the HTML code :
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_012_heart.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
</div>
<h5 id="Email" align="left" color="#000"<span style="color:black">For the answer, let us your email :</h5>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_290_skull.png"></span></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="Email">
</div>
<!-- Form itself -->
<div class="form-actions">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-primary pull-right">Send</button><br />
Here the PHP code :
<?php
ini_set(“SMTP”,”smtp.viktorius.fr”);
ini_set(“smtp_port”,”25″);
$myemail = 'postmaster#viktorius.fr';
if (isset($_POST['question'])) {
$email = strip_tags($_POST['email']);
echo "<span class=\"alert alert-success\" >Your message has been received. Thanks! Here is what you submitted:</span><br><br>";
echo "<stong>Question:</strong> ".$question."<br>";
echo "<stong>Email:</strong> ".$email."<br>";

if (isset($_POST['name']))
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
Check the name of your inputs, php cant read your post data.

There is not a single form here...
the ajax expects to serialize
<form class="contact">...
$('form.contact').serialize(),
And you don't have a form
You should put all your inputs and button inside a form tag with class contact like this:
<form action="" class="contact">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_012_heart.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
</div>
<div style="margin-bottom: 25px;" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_290_skull.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" color="#000000"placeholder="For the answer, let us your email adress here :">
</div>
<div class="form-actions">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-primary pull-right">Send</button><br>
</div>
</form>

Related

How to check if the form has been submitted on localhost

I'm trying to check if the form has been submitted. If I press the submit button, the success message will appear but when I check my mailbox I don't see any message. I'm using WampServer. I followed a YouTube tutorial where the guy has the exact same code but for some reason, it doesn't work for me.
<form action="contact.php" method="post" id="myForm">
<div class="md-form">
<i class="fas fa-user prefix grey-text"></i>
<input type="text" required name="name" id="form_name" class="form-control" />
<label for="form_name">Your name</label>
</div>
<div class="md-form">
<i class="fas fa-envelope prefix grey-text"></i>
<input type="email" required name="email" id="form_email" class="form-control" />
<label for="form_email">Your email</label>
</div>
<div class="md-form">
<i class="fas fa-tag prefix grey-text"></i>
<input type="text" name="subject" required id="form-Subject" class="form-control" />
<label for="form_subject">Subject</label>
</div>
<div class="md-form">
<i class="fas fa-pencil-alt prefix grey-text"></i>
<textarea id="form_text" name="message" class="form-control md-textarea" rows="3"></textarea>
<label for="form_text">Your message</label>
</div>
<div class="text-center mt-4">
<button class="btn contact-button text-white" type="submit" name="submit">Submit</button>
</div>
<div id="success_message" class="text-dark text-center"></div>
</form>
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['email'];
$message = $_POST['message'];
$mailTo = "patriciushorny#gmail.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an e-mail from ".$name.".\n\n".$message;
mail($mailFrom, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
?>
<form class="form-area contact-form text-right" action="mail.php" method="post">
<div class="row">
<div class="col-lg-6 form-group">
<input name="name" id="name" placeholder="Enter your name" class="common-input mb-20 form-control" type="text">
<input name="email" id="email" placeholder="Enter email address" class="common-input mb-20 form-control" type="email">
<input name="sub" id="sub" placeholder="Enter subject" class="common-input mb-20 form-control" type="text">
</div>
<div class="col-lg-6 form-group">
<textarea class="common-textarea form-control" name="desc" id="desc" placeholder="Enter Messege" ></textarea>
</div>
<div class="col-lg-12">
<button class="genric-btn primary" value="submit" id="submit" name="submit" style="float: right;">Send Message</button>
</div>
</div>
More Details view this link VIEW FULL CODE

form not sending data?

I cant for the life of me figure this out.
I have the following form which, when submitted, returns an empty array?
Its going to the right page when submitted (index.php) but its not passing anything as either GET or POST. Both return nothing using var_dump($_POST). Any ideas?
<form action="index.php" method="post">
<div class="form-group">
<label for="orderName">What is your name?</label>
<input type="textbox" class="form-control" id="orderName" aria-describedby="orderName" placeholder="Enter name">
</div>
<div class="form-group">
<label for="orderEmail">What is your email address?</label>
<input type="textbox" class="form-control" id="orderEmail" aria-describedby="orderEmail" placeholder="Enter email">
</div>
<div class="form-group">
<label for="orderCopies">How many copies of the book would you like?</label>
<input type="textbox" class="form-control" id="orderCopies" aria-describedby="orderCopies" placeholder="Enter amount of books">
<small id="oderCopiesHelp" class="form-text text-muted">Note: each book is $35 (including postage)</small>
</div>
<div class="form-group">
<label for="orderAddress">Where would you like the book/s sent to?</label>
<textarea class="form-control" id="orderAddress" rows="3"></textarea>
</div>
<div class="form-group">
<label for="orderComments">Order comments</label>
<textarea class="form-control" id="orderComments" rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Send order</button>
</form>
Input needs name attribute which is missing in your markup.
For example,
<input type="textbox" class="form-control" name="orderName" id="orderName" aria-describedby="orderName" placeholder="Enter name">
Your code with name attributes on <input>, <textarea> and <button>:
<form action="index.php" method="post">
<div class="form-group">
<label for="orderName">What is your name?</label>
<input type="textbox" class="form-control" name="orderName" id="orderName" aria-describedby="orderName" placeholder="Enter name">
</div>
<div class="form-group">
<label for="orderEmail">What is your email address?</label>
<input type="textbox" class="form-control" name="orderEmail" id="orderEmail" aria-describedby="orderEmail" placeholder="Enter email">
</div>
<div class="form-group">
<label for="orderCopies">How many copies of the book would you like?</label>
<input type="textbox" class="form-control" name="orderCopies" id="orderCopies" aria-describedby="orderCopies" placeholder="Enter amount of books">
<small id="oderCopiesHelp" class="form-text text-muted">Note: each book is $35 (including postage)</small>
</div>
<div class="form-group">
<label for="orderAddress">Where would you like the book/s sent to?</label>
<textarea class="form-control" name="orderAddress" id="orderAddress" rows="3"></textarea>
</div>
<div class="form-group">
<label for="orderComments">Order comments</label>
<textarea class="form-control" name="orderComments" id="orderComments" rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="submitButton">Send order</button>
</form>
You need to add name attribute tags for each input element. The name attribute and value gets sent via the post method to the script to receive it.
For each input tag always put the name attribute to pass the form data.
Ex.
<input type="textbox" class="form-control" id="orderName" name="orderName" aria-describedby="orderName" placeholder="Enter name">

Submit button has to be in the same form as email/pw field?

I´m quite new to php so this might just be a stupid question. Is there a way to put the submit button into another form field, or must it be the same? Does it really matter if I create a new field somewhere else?
Not working Code:
<div class="container">
<form method="post">
<div class="form-group">
<input type="text" class="form-control" name="emailfield" id="emailfeld2" placeholder="Emailadresse (z.B Max#Max.de)">
<input type="password" class="form-control" name="passwordfield" id="passwortfeld" placeholder="Passwort">
<input type="password" class="form-control" name="cpasswordfield" id="cpasswortfeld" placeholder="Passwort bestätigen">
</div>
</form>
<div class="form-group">
<form method="post">
<button type="submit" class="btn btn-success" name="submitgo">Sign Up!</button>
</form>
</div>
</div>
<?php
echo $_POST['emailfield']."<br>";
?>
<div class="container-opacity">
</div>
Working code:
<div class="container">
<form method="post">
<div class="form-group">
<input type="text" class="form-control" name="emailfield" id="emailfeld2" placeholder="Emailadresse (z.B Max#Max.de)">
<input type="password" class="form-control" name="passwordfield" id="passwortfeld" placeholder="Passwort">
<input type="password" class="form-control" name="cpasswordfield" id="cpasswortfeld" placeholder="Passwort bestätigen">
<button type="submit" class="btn btn-success" name="submitgo">Sign Up!</button>
</div>
</form>
</div>
<?php
echo $_POST['emailfield']."<br>";
?>
<div class="container-opacity">
</div>
It is generally bad practice to have form elements outside of the form they belong to. It will work if you only have one <form> tag and move it outside of you main <div class="container">
<form method="post">
<div class="container">
<div class="form-group">
<input type="text" class="form-control" name="emailfield" id="emailfeld2" placeholder="Emailadresse (z.B Max#Max.de)">
<input type="password" class="form-control" name="passwordfield" id="passwortfeld" placeholder="Passwort">
<input type="password" class="form-control" name="cpasswordfield" id="cpasswortfeld" placeholder="Passwort bestätigen">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success" name="submitgo">Sign Up!</button>
</div>
</div>
</form>
<?php echo $_POST[ 'emailfield']. "<br>"; ?>
<div class="container-opacity">
</div>

Mysql Insert form into database table PDO

I have a problem.. I tried today a lot to make this working but it seems to be impossible for me.. so I decided to ask help here. So I have a form which needs to be added on database table when submit button is pressed.
This is php code I currently use.. I removed my tries btw:
<?php
$pdo = new PDO('mysql:host=;dbname=', '', '');
$sql = "SELECT * FROM games LIMIT 10";
foreach ($pdo->query($sql) as $row) {
?>
my HTML code (form):
<form class="form-group" method="POST" action="">
<div role="tabpanel" class="tab-pane active" id="home">
<div class="form-group" style="margin-top: 15px;">
<label for="exampleInputEmail1">Game Title</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="" name="gtitle" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">YouTube Link</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="" name="ytlink" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Link Source</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="ex: GLEAM, DLH, FAILMID, HRKGAME, INDIEGALA, OTHER, STEAM" name="slink" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Link to Free Steam Keys</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="KEY MUST GIVE +1 TO THE STEAM LIBRARY GAME COUNT" name="keysl" />
</div>
<label for="exampleInputPassword1">Steam App ID</label>
<div class="input-group" style="padding-bottom: 10px;">
<span class="input-group-addon" id="basic-addon3">http://store.steampowered.com/app/</span>
<input type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3" placeholder="App ID" name="appid" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Categories</label>
<div class="checkbox">
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1" /> 1
<h4><span class="label label-success">Keys Available</span></h4>
</label>
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2" /> 2
<h4><span class="label label-danger">No Keys left</span></h4>
</label>
</div>
<button type="submit" class="btn btn-default" name="insert">Submit</button>
</div>
</div>
</form>
Thank those who help me.
Try this and in the radio button put value as '1' and '2' instead of 'option1' and 'option2'
if(isset($_POST['insert']))
{
$game_title=$_POST['gtitle'];
$youtube_link=$_POST['ytlink'];
$link_source=$_POST['slink'];
$link_steam_keys=$_POST['keysl'];
$app_id=$_POST['appid'];
$categories=$_POST['inlineRadioOptions'];
$query_ins="INSERT INTO tbl_game(game_title,youtube_link,link_source,link_steam_keys,app_id,categories) VALUES(:game_title,:youtube_link,:link_source,:link_steam_keys,:app_id,:categories)";
$stmt_query=$dbh->prepare($query_ins);
$games_ins=$stmt_query->execute(array(":game_title"=>$game_title,":youtube_link"=>$youtube_link,":link_source"=>$link_source,":link_steam_keys"=>$link_steam_keys,":app_id"=>$app_id,":categories"=>$categories));
if(!$games_ins)
{
$error=$stmt_query->errorInfo();
echo $error['2'];
}
}
You need to check the POST variables after submitting in your PHP code. If the form is submitted, take the post values and just run an INSERT query.
See $_POST

HTML - form acting weird. Not redirecting to URL and using GET instead of POST

I'm a CS student and I have a DB project due in less than 24hrs! This is really annoying because I just need to forms to access my DB. Anyway, I have this form that works perfectly, while the second form does not work. Instead of posting and directing to the correct URL the second form re-loads the current page with the variables in the URL. Anybody have any ideas?
<form role="form" method="post" action="../controller/AddPerson.php">
<div class="box-body">
<div class="form-group">
<label for="newReservationFirstName"> First name</label>
<input type="text" class="form-control" name="newReservationFirstName" placeholder="Enter first name">
<label for="newReservationLastName"> Last name</label>
<input type="text" class="form-control" name="newReservationLastName" placeholder="Enter last name">
<label for="newReservationPhoneNumber"> Phone Number</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="newReservationPhoneNum" data-inputmask='"mask": "(999) 999-9999"' data-mask/>
</div><!-- /.input group -->
<label for="newReservationStreetAddress"> Street Address</label>
<input type="text" class="form-control" name="newReservationStreetAddress" placeholder="Enter street address">
<label for="newReservationCity"> City</label>
<input type="text" class="form-control" name="newReservationCity" placeholder="Enter city">
<label for="newReservationState"> State</label>
<select class="form-control" name="newReservationState">
<?php
$result = getTableOrderBy('States','stateName');
while($row = mysql_fetch_array($result)) {
echo "<option value=".$row[stateAbbr].">".$row[stateName]."</option>";
} ?>
</select>
<label for="newReservationZip"> Zip Code</label>
<input type="text" class="form-control" name="newReservationZip" placeholder="Enter zipcode">
</div>
<button type="submit" class="btn btn-success btn-lg">Add New Customer</button>
</div>
</form>
This is the form that doesn't work correctly, both pages exist on the server:
<form role="form" method="post" action="../controller/AddEmployee.php">
<div class="box-body">
<div class="form-group">
<label for="newEmployeeFirstName"> First name</label>
<input type="text" class="form-control" name="newEmployeeFirstName" placeholder="Enter first name">
<label for="newEmployeeLastName"> Last name</label>
<input type="text" class="form-control" name="newEmployeeLastName" placeholder="Enter last name">
<label for="newEmployeePhoneNumber"> Phone Number</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="newEmployeePhoneNum" data-inputmask='"mask": "(999) 999-9999"' data-mask/>
</div><!-- /.input group -->
<label for="newEmployeeStreetAddress"> Street Address</label>
<input type="text" class="form-control" name="newEmployeeStreetAddress" placeholder="Enter street address">
<label for="newEmployeeCity"> City</label>
<input type="text" class="form-control" name="newEmployeeCity" placeholder="Enter city">
<label for="newEmployeeState"> State</label>
<select class="form-control" name="newEmployeeState">
<?php
$result = getTableOrderBy('States','stateName');
while($row = mysql_fetch_array($result)) {
echo "<option value=".$row[stateAbbr].">".$row[stateName]."</option>";
} ?>
</select>
<label for="newEmployeeZip"> Zip Code</label>
<input type="text" class="form-control" name="newEmployeeZip" placeholder="Enter zipcode">
<p></p>
<p></p>
<label for="newEmployeeFirstName"> Account Username</label>
<input type="text" class="form-control" name="newEmployeeUsername" placeholder="Enter username">
<label for="newEmployeeLastName"> Account Password</label>
<input type="text" class="form-control" name="newEmployeePassword" placeholder="Enter password">
<label for="newEmployeePhoneNumber"> Social Security Number</label>
<input type="text" class="form-control" name="newEmployeeSocial" placeholder="Enter SSN">
<div class="form-group" name="newEmployeePrivileges">
<br>
Privileges :
<select name="newEmployeePrivileges">
<option value="admin">Admin</option>
<option value="admin">Non-Admin</option>
</select>
</div>
<button type="submit" class="btn btn-success btn-lg">Add New Employee</button>
</div>
</div>
</form>
----------------------------------EDIT ----------------------------------------------
I tried making a another really simple form on some extra space and it still didn't work. I have no idea what could be cause it to do this.
<form method="post" action="post" action="../controller/AddEmployee.php">
<button type="submit" class="btn btn-success btn-lg">Add New Employee</button>
</form>
It could be that the button tag you are using to submit the form is causing it behave strangely. Try swapping out the button tag for an input. So:
<form method="post" enctype="multipart/form-data" action="../controller/AddEmployee.php">
<input type="submit" class="btn btn-success btn-lg" name="submit" >Add New Employee</input>
</form>
Also, I noticed you've included two 'action' attributes in your example form :-)

Categories