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">
Related
This is my first go at trying to create a secure login feature.
Right now I have a mysql database storing a few usernames and passwords.
I also have a bootstrap template for a login page.
Here is some of the html:
<form>
<div class="form-group">
<div class="form-label-group">
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required="required" autofocus="autofocus">
<label for="inputEmail">Email address</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required="required">
<label for="inputPassword">Password</label>
</div>
</div>
<a class="btn btn-primary btn-block" href="connect.php" method="post">Login</a>
</form>
I added the method and changed the action for the login button/link.
I would like to be able to click the login link and have the input values sent to an external php program connect.php shown below:
<!DOCTYPE html>
<html lang="en">
<body>
<div>
<?php
$user = $_POST["inputEmail"];
$pass = $_POST["inputPassword"];
echo "<h1>Hello: ".$user." also:".$pass"</h1>";
?>
</div>
</body>
</html>
Once I can get the values to send to the external script, I can then start to check the values against those in my database.
Solutions I have seen are mostly dealing with the form action and not a link. Those that are dealing with a link use get and hard code the values being sent rather than input.
EDIT 1:
I realized my html page was launching outside of my server. I made some changes to my html:
<form method="post">
<div class="form-group">
<div class="form-label-group">
<input type="email" id="inputEmail" name="inputEmail" class="form-control" placeholder="Email address" required="required" autofocus="autofocus">
<label for="inputEmail">Email address</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input type="password" id="inputPassword" name="inputPassword" class="form-control" placeholder="Password" required="required">
<label for="inputPassword">Password</label>
</div>
</div>
<a class="btn btn-primary btn-block" href="connect.php" method="post" name="submit">Login</a>
</form>
after these changes its telling me my inputs are Unidentified index's
SOLUTION
change submit link to submit button & make sure to run on a server
<form action="connect.php" method="POST">
<div class="form-group">
<div class="form-label-group">
<input type="email" id="inputEmail" name="inputEmail" class="form-control" placeholder="Email address" required="required" autofocus="autofocus">
<label for="inputEmail">Email address</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input type="password" id="inputPassword" name="inputPassword" class="form-control" placeholder="Password" required="required">
<label for="inputPassword">Password</label>
</div>
</div>
<button class="btn btn-primary btn-block" name="submit" type="submit">Login</button>
</form>
I can't submit form textarea TinyMCE. I need to be able to use many TinyMCE's, but my code only works if I don't have any.
please help me..
this is code :
<form action="action/insert.php?table=<?= $page ?>" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label" for="item">Languange</label><br/>
<label for="en"><input type="radio" name="newlang" id="en" value="en"/> English</label>
<label for="id"><input type="radio" name="newlang" id="id" value="id"/> Indonesia</label>
</div>
<div class="form-group">
<label class="control-label" for="item">Item</label>
<input type="text" name="item" id="item" value="" class="form-control" required/>
</div>
<div class="form-group">
<label class="control-label" for="code">Code</label>
<input type="text" name="code" id="code" value="" class="form-control" required/>
</div>
<div class="form-group">
<label class="control-label" for="ingred">Ingredient</label>
<textarea name="ingred" id="ingred" required></textarea>
</div>
<div class="form-group">
<label class="control-label" for="spec">Spec</label>
<textarea name="spec" id="spec" required></textarea>
</div>
<div class="form-group">
<label class="control-label" for="package">Package</label>
<textarea name="package" id="package" required></textarea>
</div>
<div class="form-group">
<label class="control-label" for="price">Price</label>
<input type="number" name="price" id="price" value="" min="0" class="form-control" required/>
</div>
<div class="form-group">
<label class="control-label" for="file">Image</label>
<input type="file" name="file" id="file" class="form-control"/>
</div>
<hr>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> Add</button>
<button type="reset" name="reset" class="btn btn-default"><i class="fa fa-refresh"></i> Reset</button>
<button type="button" name="back" class="btn btn-default" onclick="location.assign('?page=<?= $page ?>/')"><i class="fa fa-reply"></i> Back</button>
</div>
I have to add a space between the textarea
How are you actually submitting the content of the editor here? Your first step would be to call editor.getcontent() somewhere.
https://www.tinymce.com/docs/api/tinymce/tinymce.editor/#getcontent
I am trying to capture the $_POST from this form:
<?php
var_dump($_POST);
?>
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<div class="col-sm-6">
<input type="text" class="form-control input-lg" id="inputEmail3" placeholder="Name*">
</div>
<div class="col-sm-6">
<input type="email" class="form-control input-lg" id="inputPassword3" placeholder="Email*">
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<input type="text" class="form-control input-lg" id="inputPassword3" placeholder="Position">
</div>
<div class="col-sm-6">
<input type="text" class="form-control input-lg" id="inputPassword3" placeholder="Company">
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<textarea class="form-control input-lg" rows="3" cols="10" placeholder="Message"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-6 col-sm-6">
<input type="submit" class="btn btn-default btn-lg btn-custom-sbmit" value="Send" />
</div>
</div>
</form>
and some how I keep failing because when I enter the details, and hit submit I get and array back: array(0) { }.
This is probably one of the most basic things, yet I forgot ow to do it. Ideas?
You have no name attributes for your <input> form elements. As a result nothing is sent to the server. You can verify this by using Firebug or Chrome's developer tools to see no data is sent.
<input type="text" class="form-control input-lg" id="inputEmail3" placeholder="Name*">
should be
<input type="text" class="form-control input-lg" name="inputEmail3" placeholder="Name*">
etc.
I have a form like below:
<form id="bookForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0].title" placeholder="Title" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0].isbn" placeholder="ISBN" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" name="book[0].price" placeholder="Price" />
</div>
<div class="col-xs-1">
<button type="button" class="btn btn-default addButton"><i class="fa fa-plus"></i></button>
</div>
</div>
How to get value of this form in php $_Post because the name of fields are like <br/>name="book[0].title"**<br/>?
and there are many dynamic different name input fields.
If you can use for multiple books then use book[0].title like below,
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][title]" placeholder="Title" />
</div>
If you want to use same form then change name of all textbox like,
<form id="bookForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][title]" placeholder="Title" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][isbn]." placeholder="ISBN" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" name="book[0][price]" placeholder="Price" />
</div>
<div class="col-xs-1">
<button type="submit" class="btn btn-default addButton"><i class="fa fa-plus"></i></button>
</div>
</div>
And get value of this form like echo $_POST['book'][0]['title'];
I hope this can help you.
You need to change name attribute,
<div class="col-xs-4">
<input type="text" class="form-control" name="book_title" placeholder="Title" />
</div>
book[0].title, this is not valid name.
You can now get something like this,
$_POST['book_title']
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 :-)