I want to create a simple HTML form (ideally using bootstrap).
On this form some input elements are filled by the user(which is simple!) but I also need to call an API with json data to fill a drop down box. like list of countries,etc.
How can I implement API into a form?
thanks
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>My form</legend>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="title">Title</label>
<div class="controls">
<input id="title" name="title" type="text" placeholder="Article on Banking,etc." class="input-medium">
</div>
</div>
<!-- Select Basic -->
<div class="control-group">
<label class="control-label" for="Article Type">Article Type</label>
<div class="controls">
<select id="Article Type" name="Article Type" class="input-xlarge">
<option>ashkanarvaneh.co.uk/test/api.json</option>
</select>
</div>
</div>
<!-- Textarea -->
<div class="control-group">
<label class="control-label" for="summary">Summary</label>
<div class="controls">
<textarea id="summary" name="summary">Enthusiastically strategize superior infomediaries after clicks-and-mortar process improvements. Appropriately incubate stand-alone methodologies vis-a-vis pandemic potentialities. Authoritatively build.</textarea>
</div>
</div>
<!-- Button -->
<div class="control-group">
<label class="control-label" for="submit">Submit</label>
<div class="controls">
<button id="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
Try Example
<!-- Select Basic -->
<div class="control-group">
<label class="control-label" for="Article Type">Article Type</label>
<div class="controls">
<select id="Article Type" name="Article Type" class="input-xlarge">
<?php
$countries = file_get_contents("http://ashkanarvaneh.co.uk/test/api.json");
$countries = json_decode($countries, true);
foreach($countries as $country)
{
echo "<option value='".$country['Id']."'>".$country['Description']."</option>";
}
?>
<!--<option>http://publicapidev.chambersandpartners.com/api/taggedlocations</option>-->
</select>
</div>
</div>
Note The above code is tested & works fine.
Related
The contact form has several text fields and several dropdowns with the ability to select multiple values. The question is how to send these values by e-mail? Text values of type string (one word at a time) are sent fine. But how to send arrays containing multiple values? How to collect them using the $_POST method and put them in a letter?
Form:
<section class="post-content-area pt-20">
<div class="container">
<div class="row">
<div class="col-lg-8 posts-list">
<div class="card card-signin my-5">
<div class="card-body">
<h5 class="card-title text-center" style="font-size: 26px">Test contact form</h5>
<form method="post" action="email-script.php" enctype="multipart/form-data" id="emailForm">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" placeholder="Name" >
<div id="nameError" style="color: red;font-size: 14px;display: none">nameError</div>
</div>
<div class="form-group">
<input type="text" name="surname" id="surname" class="form-control" placeholder="Surame" >
<div id="nameError" style="color: red;font-size: 14px;display: none">nameError</div>
</div>
<div class="form-group">
<input type="text" name="phone" id="phone" class="form-control" placeholder="Phone" >
<div id="subjectError" style="color: red;font-size: 14px;display: none">subjectError</div>
</div>
<div class="form-group">
<label>First Level Category</label><br />
<select id="first_level" name="first_level[]" multiple class="form-control">
<?php
foreach($result as $row)
{
echo '<option value="'.$row["first_level_category_id"].'">'.$row["first_level_category_name"].'</option>';
}
?>
</select>
</div>
<div class="form-group">
<label>Second Level Category</label><br />
<select id="second_level" name="second_level[]" multiple class="form-control">
</select>
</div>
<div class="form-group">
<label>Third Level Category</label><br />
<select id="third_level" name="third_level[]" multiple class="form-control">
</select>
</div>
<div class="form-group">
<input type="file" name="attachment" id="attachment" class="form-control">
<div id="attachmentError" style="color: red;font-size: 14px;display: none">attachmentError</div>
</div>
<div class="submit">
<center><input type="submit" name="submit" onclick="return validateEmailSendForm();" class="btn btn-success" value="SUBMIT"></center>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
Emailing script:
https://pastebin.com/3SR67MUP
There are multiple ways on how to send them via email.
The easiest way is getting them on your form action page and sending them with the php mail() function.
To make the email look better you can create an HTML email template file.
Then get the file data with file_get_contents() and resetting strings with your collected data with the str_replace function and putting the data into your mail funtion.
Hope it helps!
i have a little bit error when doing a simple registration form. My problem is the data that have input is not inserted in database.
But before i using horizontal form the data can be inserted in my database. I'm using MySQL. this is my controller :
function create(){
$data = array(
'nik' => $this->input->post('nik'),
'nama' => $this->input->post('nama'),
'tgl_lahir' =>$this->input->post('tgl_lahir'),
'no_hp' => $this->input->post('no_hp'),
'alamat' => $this->input->post('alamat')
);
$this->db->insert('profile_mitra',$data);
redirect('admin/daftar_mitra');
}
and this my view called tambah_mitra.php.
View (tambah_mitra.php)
<?php $this->load->view('templates/head');?>
<?php $this->load->view('templates/sidebar');?>
<body>
<div class="content-wrapper">
<section class="content-header">
<section class="content">
<div class="row">
<!-- left column -->
<div class="col-md-6">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Tambah Mitra</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form role="form">
<div class="box-body">
<div class="form-group">
<?php echo validation_errors();?>
<?php echo form_open('admin/daftar_mitra');?>
<label for="exampleInputEmail1">NIK</label>
<input type="text" class="form-control" id="nik" placeholder="NIK">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Nama</label>
<input type="text" class="form-control" id="nama" placeholder="Nama">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Tanggal Lahir</label>
<input type="date" class="form-control" id="tgl_lahir" placeholder="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">No.HP</label>
<input type="text" class="form-control" id="no_hp" placeholder="Nomor Handphone">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Alamat</label>
<input type="alamat" class="form-control" id="alamat" placeholder="Alamat Lengkap">
</div>
<!-- <div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
<p class="help-block">Example block-level help text here.</p>
</div> -->
<!-- <div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div> -->
</div>
<!-- /.box-body -->
<div class="box-footer">
<input class="btn btn-success" type="submit" value="Simpan">
</div>
</form>
</div>
</div>
</div>
</section>
</div>
</body>
<?php $this->load->view('templates/footer');?>
it is not inserting because you did not define name of input filed.i think this is the reason of not inserting data. please try.
<div class="form-group">
<label for="exampleInputEmail1">Nama</label>
<input type="text" class="form-control" id="nama" name="nama" placeholder="Nama">
</div>
try closing your form
<?php echo form_close();?>
Also to see the errors use
<?php echo form_error('nik');
and continue filling the (' ') in with your variables
to see what the error is.
I am working on invoice where I have to save form's data in database and at the same time it should be print. So, I have 3 pages: invoice.php, invoice_print.php and insert_data.php
invoice_print.php is a html form that should be printed.
Now, user will go to first invoice.php then he will fill details and either he will click on submit button to save data in db or else he will click on print button to print that invoice.
Now, lets come to the second part: If user will select print button then data will go to database first and then it will go to invoice_print.php with same data that he filled.
How to do this? What logic should I use to save data and capture that data's id in button and then send that id on another page to display?
invoice.php:
<form id="demo-form2" action="insert_data.php" method="post" data-parsley-validate class="form-horizontal form-label-left">
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Location</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="designation">
</div>
</div>
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Address</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="contact">
</div>
</div>
</form>
invoice_print.php:
<div class="col-md-12">
<div class="col-md-6">
<h2>DIGILIFE BIZCARE SOLUTIONS</h2>
<p>414, Vashi Infotech Park,Maharashtra</p>
</div>
<div class="col-md-6">
<h2>BILL OF SUPPLY</h2>
</div>
</div>
<div class="col-md-12">
<div class="col-md-6">
<div class="col-md-12">
<div class="col-md-6">
<label>GSTIN</label>
<input type="text" name="gstin" value="">
<label>Serial No & Date of Invoice</label>
<input type="text" name="serialNo">
</div>
<div class="col-md-6">
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-12">
<div class="col-md-6">
<label>Mode of Transport</label><br>
<label>Vehicle No</label><br>
<label>Date & Time of Supply</label><br>
<label>Place Of Supply</label>
</div>
<div class="col-md-6s">
<input type="text" name="">
<input type="text" name="">
<input type="text" name="">
<input type="text" name="">
</div>
</div>
</div>
</div>
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Location</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="designation">
</div>
</div>
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Address</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="contact">
</div>
</div>
I would put all of the code for a form into one file, structured thus:
<?php
$formDone=!empty($_POST['formDone']);
$printReq=!empty($_POST['printReq']);
if ($formDone)
{
// perform validation
}
if ($formDone && $validationPassed)
{
// write to database using $_POST data
}
if ($formDone && $databaseWriteSuccess && $printReq)
{
// print using $_POST data
}
// end of PHP
?>
<form method="post" action="<?php echo $PHP_SELF ?>">
<fieldset>
<input type="hidden" name="formDone" value="1" />
</fieldset>
<!-- field forms -->
<input type="submit" value="Save to db" />
<input type="submit" name="printReq" value="Print Invoice" />
</form>
I've read the other answers to my question regarding combining both the select and text fields, but when I try to apply any of the solutions to my form it does not work.
Can someone modify my form so that you end up with a dropdown containing both the select options and a text input field?
Please include the appropriate jquery script as well.
Here is my form code:
<form id="ajax-contact-form" action="drumming_for_jared_registration.php" method="post">
<div class="row">
<div class="span12">
<div class="control-group">
<label class="control-label" for="inputName">Date:</label>
<div class="controls">
<input class="span4" type="text" id="inputName" name="Date" placeholder="Date:" style="color:white" onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='Date:' ) this.value=''">
</div>
</div>
</div>
<div class="row"></div>
<div class="span4">
<div class="control-group">
<label class="control-label" for="inputName">New To Studio?</label>
<div class="controls">
<select input class="span14" type="text" id="inputLevel" name="New_to_Studio">
<option>New To Studio?</option>
<option>Yes</option>
<option>No</option>
</select>
</div>
</div>
</div>
<div class="row"></div>
</div>
<button type="submit" class="submit">Send</button>
</form>
I am working on a website which I didn't create and to which I do not have full access (I can create a page and add html scripts but not much more)
I am trying to add a form which will send data to be processed by a third-party servlet.
I am trying to include in this form the client ID, which I saw can be retrieved using the php functionsession_id().
My question is, how to send this information along with the rest of the input data.
my form for now is this:
<form class="form-horizontal" action = "url" method="POST" target="_blank">
<fieldset>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">Culture</label>
<div class="col-md-4">
<select id="Crop" name="Crop" class="form-control">
<option value="1">Maïs</option>
<option value="2">Ble</option>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">Produit</label>
<div class="col-md-4">
<select id="Product" name="Product" class="form-control">
<option value="Iodure d'azote">Iodure D'azote</option>
<option value="Desherbant">Desherbant</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="area">Surface</label>
<div class="col-md-4">
<input id="Area" name="Area" type="text" placeholder=" " class="form-control input-md" required="">
<span class="help-block">en Ha</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="dose">Dosage</label>
<div class="col-md-4">
<input id="Dose" name="Dose" type="text" placeholder="" class="form-control input-md" required="">
<span class="help-block">en L/Ha</span>
</div>
</div>
<div class="form-group">
<!--need to get the actual id-->
<input type="hidden" value="1" name = "ID"/>
<input type="submit" value="Ajouter" />
</div>
</fieldset>
</form>
Since this is my first time handling web apps, is there something obvious i'm missing?
OK i was lacking basic understanding of php. sorry for bothering,
the answer was here
i just had to write
<input type="hidden" value="<?php echo session_id();?>" name = "ID"/>
instead of
<input type="hidden" value="1"name = "ID"/>