Autocomplete attribute in html form not working - php

I want to have an update option in my html form in which user enters First_name then all the fields should be autofilled with corresponding values in mysql table.
I tried to use autocomplete attribute in few fields and it is not working.Please check the code and let me know if there is any error.Or any other way to implement the requirement.
<form method="post" action="demo1.php" autocomplete="on">
<link rel="stylesheet" href="contact_css.css">
<!--Create a table -->
<table>
<tr><td><b>Contact Information</b></td>
</tr>
<tr>
<div class="leftside">
<td>ContactID</td>
<td><input type="text" name="ContactID" autocomplete="ContactID"></td>
</div>
<div class="rightside">
<td>ContactOwner</td>
<!-- <td><input type="text" name="ContactOwner"></td>-->
<td><select name="ContactOwner">
<option value="None">None</option>
<option value="Malik">Malik</option>
<option value="Manish">Manish</option>
<option value="Ankit">Ankit</option>
<option value="Vikrant">Vikrant</option>
</select></td>
</div>
<tr>
<div class="rightside">
<td>LeadSource</td>
<td><select name="LeadSource">
<option value="None">None</option>
<option value="Advertisement">Advertisement</option>
<option value="ColdCall">ColdCall</option>
<option value="EmployeeReferral">EmployeeReferral</option>
<option value="ExternalReferral">ExternalReferral</option>
<option value="OnlineStore">OnlineStore</option>
<option value="Partner">Partner</option>
<option value="Web">Web</option>
<option value="TradeShow">TradeShow</option>
</select></td>
<!--<td><input type="text" name="LeadSource"></td>-->
</div>
<div class="leftside">
<td><label for="First_name">First_name</td>
<td><input type="text" id="First_name" name="First_name" autocomplete="First_name"></td>
</div>
</tr>
<tr>
<div class="rightside">
<td>Middle_name</td>
<td><input type="text" name="Middle_name" autocomplete="Middle_name"></td>
</div>
<td>Last_name</td>
<td><input type="text" name="Last_name" autocomplete="Last_name"></td>
</tr>
<tr>
<td>AccountName</td>
<td><input type="text" name="AccountName"></td>
<td>EmailID</td>
<td><input type="text" name="EmailID"></td>
</tr>
<tr>
<td>Department</td>
<td><input type="text" name="Department"></td>
<td>Phone</td>
<td><input type="text" name="Phone"></td>
</tr>
<tr>
<td>Mobile</td>
<td><input type="number" name="Mobile"></td>
<td>Fax</td>
<td><input type="number" name="Fax"></td>
</tr>
<tr>
<td>DOB</td>
<td><input type="date" name="DOB"></td>
<td>Assistant</td>
<td><input type="text" name="Assistant"></td>
</tr>
<tr>
<td>AsstPhone</td>
<td><input type="number" name="AsstPhone"></td>
<td>ReportsTo</td>
<td><input type="text" name="ReportsTo"></td>
</tr>
<tr>
<td>LinkedIn</td>
<td><input type="text" name="LinkedIn"></td>
<td>CallStatus</td>
<td><select name="CallStatus">
<option value="None">None</option>
<option value="AnsweringMachine">AnsweringMachine</option>
<option value="Callback">Callback</option>
<option value="NotInterested">NotInterested</option>
<option value="Prospect">Prospect</option>
<option value="WrongContact">WrongContact</option>
<option value="PerformedInternally">PerformedInternally</option>
<option value="LessThan30Employee">LessThan30Employee</option>
</select></td>
</tr>
</table>
<!-- Second table-->
<table>
<tr><td><b>Address Information</b></td>
</tr>
<tr>
<div class="leftside">
<td>Street</td>
<td><input type="text" name="Street"></td>
</div>
<div class="rightside">
<td>OtherStreet</td>
<td><input type="text" name="OtherStreet"></td>
</div>
</tr>
<tr>
<div class="leftside">
<td>City</td>
<td><input type="text" name="City"></td>
</div>
<div class="rightside">
<td>State</td>
<td><input type="text" name="State"></td>
</div>
</tr>
<tr>
<td>Zip</td>
<td><input type="text" name="Zip"></td>
<td>Country</td>
<td><input type="text" name="Country"></td>
</tr>
</table>
<!--Third table-->
<table>
<tr><td><b>Description Information</b></td>
</tr>
<tr>
<td>Description</td>
<td><input type="text" name="Description" class="Description"></td>
</table>
<button type="button">Cancel</button>
<!-- <button type="submit">Save and New</button>-->
<button type="submit">Save</button>
</form>
</body>

This is not how autocomplete attribute is working.
Definition and Usage
The autocomplete attribute specifies whether or not an input field
should have autocomplete enabled.
Autocomplete allows the browser to predict the value. When a user
starts to type in a field, the browser should display options to fill
in the field, based on earlier typed values.
Note: The autocomplete attribute works with the following
types: text, search, url, tel, email, password, datepickers, range,
and color.
SYNTAX
<input autocomplete="on|off">
This attribute can have only value on or off
Refer to w3schools docs for more details
If you want to have a default value in those fields you can set it inside value attribute or design your database with DEFAULT values.
So you can change <input type="text" name="ContactID" autocomplete="ContactID"> to <input type="text" name="ContactID" value="ContactID">

Related

Check if record exists and autofill the id from mysql table

When user fills the form, if LinkedIn Id already exists, it should throw an error saying LinkedIn Id already exists..
Form is not saving data if user does not enter ContactID. ContactID is an auto-increment field in MySQL table. Since more than one user works on the same form at the same time, I want ContactID to be auto-filled by the next available number from MySQL table.
Here, is my HTML form code and following, the PHP code. If you require any other details to debug, please ask.
<html>
<body>
<form method="post" action="demo.php">
<link rel="stylesheet" href="contact_css.css">
<!--Create a table -->
<table>
<tr><td><b>Contact Information</b></td>
</tr>
<tr>
<div class="leftside">
<td>ContactID</td>
<td><input type="text" name="ContactID"></td>
</div>
<div class="rightside">
<td>ContactOwner</td>
<!-- <td><input type="text" name="ContactOwner"></td>-->
<td><select name="ContactOwner">
<option value="None">None</option>
<option value="Malik">Malik</option>
<option value="Ankit">Ankit</option>
<option value="Vikrant">Vikrant</option>
</select></td>
</div>
</tr>
<tr>
<div class="rightside">
<td>LeadSource</td>
<td><select name="LeadSource">
<option value="None">None</option>
<option value="Advertisement">Advertisement</option>
<option value="ColdCall">ColdCall</option>
<option value="LinkedIn">LinkedIn</option>
<option value="Web">Web</option>
</select></td>
<!--<td><input type="text" name="LeadSource"></td>-->
</div>
<div class="leftside">
<td>First_name</td>
<td><input type="text" name="First_name"></td>
</div>
</tr>
<tr>
<div class="rightside">
<td>Last_name</td>
<td><input type="text" name="Last_name"></td>
<td>AccountName</td>
<td><input type="text" name="AccountName"></td>
</tr>
<tr>
<td>Title</td>
<td><input type="text" name="Title"></td>
<td>EmailID</td>
<td><input type="text" name="EmailID"></td>
</tr>
<tr>
<td>Industry</td>
<td><input type="text" name="Industry"></td>
<td>Department</td>
<td><input type="text" name="Department"></td>
</tr>
<tr>
<td>Phone</td>
<td><input type="text" name="Phone" required></td>
<td>Mobile</td>
<td><input type="text" name="Mobile"></td>
</tr>
<tr>
<td>Today_date</td>
<td><input type="date" name="Today_date"></td>
<td>LinkedIn</td>
<td><input type="text" name="LinkedIn"></td>
</tr>
<tr>
<td>CallStatus</td>
<td><select name="CallStatus">
<option value="None">None</option>
<option value="AnsweringMachine">AnsweringMachine</option>
<option value="Callback">Callback</option>
<option value="NotInterested">NotInterested</option>
<option value="Prospect">Prospect</option>
<option value="WrongContact">WrongContact</option>
<option value="PerformedInternally">PerformedInternally</option>
<option value="LessThan30Employee">LessThan30Employee</option>
</select></td>
<td>Website</td>
<td><input type="text" name="Website"></td>
</tr>
</table>
<!-- Second table-->
<table>
<tr><td><b>Address Information</b></td>
</tr>
<tr>
<div class="leftside">
<td>Street</td>
<td><input type="text" name="Street"></td>
</div>
<div class="rightside">
<td>OtherStreet</td>
<td><input type="text" name="OtherStreet"></td>
</div>
</tr>
<tr>
<div class="leftside">
<td>City</td>
<td><input type="text" name="City"></td>
</div>
<div class="rightside">
<td>State</td>
<td><input type="text" name="State"></td>
</div>
</tr>
<tr>
<td>Zip</td>
<td><input type="text" name="Zip"></td>
<td>Country</td>
<td><input type="text" name="Country"></td>
</tr>
</table>
<!--Third table-->
<table>
<tr><td><b>Description Information</b></td>
</tr>
<tr>
<td>Description</td>
<td><input type="text" name="Description" class="Description"></td>
</table>
<button type="button">Cancel</button>
<button type="button" class="button2" onclick="window.location.href='fetch_data.php'" />View</button>
<button type="button" class="button3" onclick="window.location.href='exm_list.php'" />Edit</button>
<button type="submit">Add</button>
</form>
< /body>
</html>
PHP Code:
<?php
// create a variable
if (isset($_POST)){
$ContactID=$_POST['ContactID'];
$ContactOwner=$_POST['ContactOwner'];
$LeadSource=$_POST['LeadSource'];
$First_name=$_POST['First_name'];
$Last_name=$_POST['Last_name'];
$AccountName=$_POST['AccountName'];
$Title=$_POST['Title'];
$EmailID=$_POST['EmailID'];
$Industry=$_POST['Industry'];
$Department=$_POST['Department'];
$Phone=$_POST['Phone'];
$Mobile=$_POST['Mobile'];
$Today_date=$_POST['Today_date'];
$LinkedIn=$_POST['LinkedIn'];
$CallStatus=$_POST['CallStatus'];
$Website=$_POST['Website'];
$Street=$_POST['Street'];
$OtherStreet=$_POST['OtherStreet'];
$City=$_POST['City'];
$State=$_POST['State'];
$Zip=$_POST['Zip'];
$Country=$_POST['Country'];
$Description=$_POST['Description'];
}
//create connection
$connect=mysqli_connect('localhost','root','','contacts');
$check="SELECT COUNT(*) FROM contact where ContactID='$_POST[ContactID]' ";
$result=mysqli_query($connect,$check);
$data=mysqli_fetch_array($result, MYSQLI_NUM);
if($data[0] > 1){
echo "LinkedIn id already exists";
}
else {
$newUser="INSERT INTO contact(ContactID,ContactOwner,LeadSource,First_name,Last_name,AccountName,Title,EmailID,Industry,Department,Phone,Today_date,LinkedIn,CallStatus,Website,Street,OtherStreet,City,State,Zip,Country,Description)
VALUES('$ContactID','$ContactOwner','$LeadSource','$First_name','$Last_name','$AccountName','$Title','$EmailID','$Industry','$Department','$Phone','$Today_date','$LinkedIn','$CallStatus','$Website','$Street','$OtherStreet','$City','$State','$Zip','$Country','$Description')";
if (mysqli_query($connect,$newUser))
{
echo "Information Added<br/>";
}
else
{
echo "Error adding user in database, ContactID exists.<br/>";
}
}
Try changing:
$check="SELECT COUNT(*) FROM contact where ContactID='$_POST[ContactID]' ";
to
$check="SELECT COUNT(*) FROM contact where ContactID='$ContactID' ";
Also:
Form is not saving data if user do not enters ContactID. *** ContactID
is an autoincrement field in mysql table.
In your insert do not include
ContactID,
since this is an autoincrement field as you mention. What you should do instead is to do this:
//create connection
$connect=mysqli_connect('localhost','root','','contacts');
$check="SELECT COUNT(*) FROM contact where ContactID='$ContactID' ";
$result=mysqli_query($connect,$check);
$data=mysqli_fetch_array($result, MYSQLI_NUM);
if($data[0] > 1){
echo "LinkedIn id already exists";
}else {
$newUser="INSERT INTO contact(ContactOwner,LeadSource,First_name,Last_name,AccountName,Title,EmailID,Industry,Department,Phone,Today_date,LinkedIn,CallStatus,Website,Street,OtherStreet,City,State,Zip,Country,Description)
VALUES('$ContactOwner','$LeadSource','$First_name','$Last_name','$AccountName','$Title','$EmailID','$Industry','$Department','$Phone','$Today_date','$LinkedIn','$CallStatus','$Website','$Street','$OtherStreet','$City','$State','$Zip','$Country','$Description')";
if (mysqli_query($connect,$newUser))
{
echo "Information Added<br/>";
}
}

'' is not a valid value for the type xsd:date (PHP)

I have an HTML form that posts all the gathered information (i.e. when the user enters the details and clicks on submit) it will post to the to a PHP script for processing. The problem is that when I do not pass any value for the date fields, I am getting the error below.
Error: '' is not a valid value for the type xsd:date
How can I make my post accept a null value for the fields and successfully submit?
Form.html:
<form class="form-horizontal" action="CandidateCreationPage.php" method="post" enctype="multipart/form-data">
<table class="form-table">
<tbody>
<tr>
<td class="label-cell"><label>First Name <span class="required-input letters-only">*</span></label></td>
<td>
<input class="required-field letters-only" type="text" name="firstname" id="first-name" maxlength="25" />
</td>
</tr>
<tr>
<td class="label-cell"><label>Last Name <span class="required-input">*</span></label></td>
<td>
<input class="required-field letters-only" type="text" name="lastname" id="last-name" maxlength="30" />
</td>
</tr>
<tr>
<td class="label-cell"><label>How Did You Learn of This Opportunity? <span class="required-input">*</span></label></td>
<td>
<select class="required-field" id="hear-this-opportunity" name="hearthisopportunity">
<option value="">--None--</option>
<option value="Kijiji">Kijiji</option>
</select>
</td>
</tr>
<tr>
<td class="label-cell"><label>Please Specify (If Applicable) <span id="please-specify-asterisk" class="required-input hide">*</span></label></td>
<td>
<input class="letters-only" type="text" name="pleasespecify" id="please-specify" maxlength="50" />
</td>
</tr>
<tr>
<td class="label-cell"><label>Status</label></td>
<td>
<select id="status" name="status">
<option value="">--None--</option>
<option value="Full-time">Full-time</option>
</select>
</td>
</tr>
<tr>
<td class="label-cell"><label>Have You Worked With Us Before?</label></td>
<td>
<select id="worked-previously" name="workedpreviously">
<option value="">--None--</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</td>
</tr>
<tr>
<td class="label-cell"><label>When (If Applicable)</label></td>
<td>
<input type="text" name="workedpreviouslywhen" id="worked-previously-when" />
</td>
</tr>
<tr>
<td class="label-cell"><label>Available to Start</label></td>
<td>
<input type="text" name="availabletostart" id="available-to-start" />
</td>
</tr>
<tr>
</form>
</body>
</html>
Post.PHP
if(isset($_POST['submit']))
{
try{
$fields = array (
'First_Name__c' => $_POST['firstname'],
'Last_Name__c' => $_POST['lastname'],
'Primary_contact_number__c'=>$_POST['primarycontactnumber'],
'Secondary_contact_number__c'=>$_POST['secondarycontactnumber'],
'Email__c'=> $_POST['email'],
'How_did_you_learn_of_this_Opportunity__c'=>$_POST['hearthisopportunity'],
'Please_Specify__c'=>$_POST['pleasespecify'],
'Status__c'=>$_POST['status'],
'Have_you_worked_with_us_before__c'=>$_POST['workedpreviously'],
'When__c'=>$_POST['workedpreviouslywhen'],
'Available_to_start__c'=>$_POST['availabletostart'],);
as an alternative way You can remove date related variables from the first array declaration and thereafter You can check if date variables are not empty and append them to your fields array.
$fields = array (
'First_Name__c' => $_POST['firstname'],
'Last_Name__c' => $_POST['lastname'],
etc
}
remove from $fields array variables like:
["When__c"]=>
["Available_to_start__c"]
and then lets check, and append variables to an array if they are not empty:
if(!empty($_POST['When'])){
$fields['When__c'] = $_POST['When'];
}
if(!empty($_POST['AvlToStart'])){
$fields['Available_to_start__c'] = $_POST['AvlToStart'];
}
etc

Pass multiple values of same data field through POST

I'm trying to pass multiple values from same parameters of a form using POST, but can't figure out how to proceed. I've used bootstrap css such that I can add multiple products. And I want to process the data of multiple orders by passing the values using POST method.
On clicking 'Add another' link, additional set of data field appear which enables recording of multiple transactions of a same user.
The code is as follows:
<div class="col-xs-5 col-lg-offset-3">
<form action="billingProceed.php" method="post" role="form">
<table id="itemElement">
<tr>
<td>
<select class="form-control">
<option class="form-control"> Customer Name</option>
<option class="form-control"> Customer ID</option>
</select>
</td>
<td><input type="text" name="<?php echo $data["name"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td>
<select class="form-control">
<option class="form-control"> Item Name</option>
<option class="form-control"> Item ID</option>
</select>
</td>
<td ><input type="text" name="<?php echo $data["item"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td style="float:right;">Quantity
</td>
<td><input type="text" name="<?php echo $data["quantity"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td style="float:right;">Price
</td>
<td><input type="text" name="<?php echo $data["price"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td style="float:right;">Discount
</td>
<td><input type="text" name="<?php echo $data["discount"]; ?>" class="form-control" /></td>
</tr>
</table>
<input type="submit" value="Proceed" class="btn btn-primary" />
<p style="float:right;">Add another</p>
You can use an array name.
Example:
<input name="data['name'][1]">
<input name="data['name'][2]">
Firstly you should be aware of the name array, for input names.
HTML Example:
<form>
<a id="add_another" href="#">Add Another</a>
<table>
<tr class="product_item">
<td>
<input type="text" name="product[1][name]" value=""/>
</td>
<td>
<input type="text" name="product[1][item]" value=""/>
</td>
</tr>
<tr id="dummy">
<td>
<input type="text" name="product[0][name]" value=""/>
</td>
<td>
<input type="text" name="product[0][item]" value=""/>
</td>
</tr>
</table>
</form>
On POST, in your PHP script, you will access them as follows:
foreach($_POST['product'] as $product)
{
$name = $product['name'];
$item = $product['item'];
}
Shoot for the JS
//You'll always start with one product row.
var productCount = 1;
$('#add_another').click(function() {
var dummyproduct = $('#dummy').clone();
//Increment Product count
productCount += 1;
//Rename all inputs
dummyproduct.find('input[name^="product[0]"]').each(function(){
$(this).attr('name',$(this).attr('name').replace('product[0]','product['+productCount +']'));
});
//Remove Id from cloned dummy
dummyproduct.removeAttr('id').addClass('product_item');
//Insert row before Dummy
dummyproduct.insertBefore('#dummy');
});

javascript change remaining dropdown values depending on first

My HTML table populates its rows dynamically. One of the table data is a dropdown with thesame options. What I want to do is when I change the value of the first, the remaining dropdowns on the other rows will have a selected value, thesame as what is recently selected.
If I change the selected value on the second row, the rest of the dropdowns will be like the second, without affecting the value of the first. Here are a few codes:
<table id="CheckDetails" width="60%">
<tr>
<th>Date</th>
<th>Category</th>
<th>Description</th>
<th>Amount</th>
</tr>
<tr class="row1">
<td><input name="date1" id="date1" class="" value="22-09-2013" /></td>
<td><select name="category" id="cat0" class="dropdown" >
<option value="0">[-- Please Choose --]</option>
<option value="1">References</option>
<option value="2">Inspirational</option>
</select>
</td>
<td><input type="text" class="entry" name="desc" id="desc0" value="1"/></td>
<td><input type="text" class="entry" name="amt" value="420.83333333333"/></td>
</tr>
<tr class="row1">
<td><input name="date1" id="date1" class="" value="22-09-2013" /></td>
<td><select name="category" id="cat0" class="dropdown" >
<option value="0">[-- Please Choose --]</option>
<option value="1">References</option>
<option value="2">Inspirational</option>
</select>
</td>
<td><input type="text" class="entry" name="desc" id="desc0" value="1"/></td>
<td><input type="text" class="entry" name="amt" value="420.83333333333"/></td>
</tr>
<tr class="row1">
<td><input name="date1" id="date1" class="" value="22-09-2013" /></td>
<td><select name="category" id="cat0" class="dropdown" >
<option value="0">[-- Please Choose --]</option>
<option value="1">References</option>
<option value="2">Inspirational</option>
</select>
</td>
<td><input type="text" class="entry" name="desc" id="desc0" value="1"/></td>
<td><input type="text" class="entry" name="amt" value="420.83333333333"/></td>
</tr>
I am working with php for this project. Any help is appreciated. Thanks!
Try
$('select[name="category"]').change(function(){
var $this = $(this), $nextAll = $this.closest('tr').nextAll('tr').find('select[name="category"]');
$nextAll.val($this.val())
});
Demo: Fiddle

Adding more field to PHP form (user can add more than one address)

My users can enter more than one address but I want an actual button that generates the extra fields as only one address is compulsory and empty fields will look ugly! I also need the extra addresses to go into mysql database.
How would I do with Javascript if PHP is not possible
Some code that may help:
<td width="732" valign="top"><p>
<h3 class="main">Address Details</h3>
<p class="normal"> You are able to add up to 3 addresses but only 1 is compulsory.
However it would be helpful if you could insert 3 addresses:
<ul>
<li>Permanent home address</li>
<li>Postal address (where you will be from June to September)</li>
<li>Local address (where you currently live)</li>
</ul>
<?php
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* $e <br>";
}
echo "</div>";
}
?>
<br>
<form action="address.php" method="post" name="regForm" id="regForm" >
<table width="95%" border="0" cellpadding="3" cellspacing="3" class="forms">
<tr>
<td>Street<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Street" type="text" id="Street" class="required" size="50">
</tr>
<tr>
<td>Line 2
</td>
<td><input name="Line2" type="text" id="Line2" class="required" size="50">
</tr>
<tr>
<td>Line 3
</td>
<td><input name="Line3" type="text" id="Line3" class="required" size="50">
</tr>
<tr>
<td>Town<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Town" type="text" id="Town" class="required" size="30">
</tr>
<tr>
<td>Postcode<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Postcode" type="text" id="Postcode" class="required" size="10">
</tr>
<tr>
<td>Country <font color="#CC0000">*</font></span></td>
<td><select name="Country" class="required" id="select8">
<option value="" selected></option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
(etc)
</select></td>
</tr>
<tr>
<td>Telephone Number<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Tele" type="text" id="Tele" class="required" >
</tr>
<tr>
<td>Fax<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Fax" type="text" id="Fax" class="required" >
</tr>
<tr>
<td>Mobile<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Mobile" type="text" id="Mobile" class="required" >
</tr>
<tr>
<td>Type <font color="#CC0000">*</font></span></td>
<td><select name="Type" class="required" id="select8">
<option value="" selected></option>
<option value="H">Home</option>
<option value="P">Postal</option>
<option value="L">Local</option>
</table>
<p align="center">
<input name="doAddress" type="submit" id="doAddress" value="Submit">
to fix your parse error - put ; at the end of line $numrows = 0 + $_GET['numrows']
to generate more fields dynamically - use javascript, really, it's way better for this task than php

Categories