I'm trying to duplicate 4 input text. For example I want to duplicate 'Produk Simpanan Saham', then only 4 input on 'Produk Simpanan Saham' div will be duplicated. I already tried a few methods using jQuery but it seem doesn't work.
<form action="" method="post" class="form-horizontal">
<br><br>
<div class="form-group">
Upload File :
<input type="file" name="file">
</div>
<div class="saham">
<div class="w3-container w3-black">
<h3>
<center>Produk Simpanan Saham</center>
</h3>
</div>
<label for="kp_produk">Kode Produk :</label>
<input type="text" name="kp_produk" class="form-control">
<br>
<label for="produk_saham">Produk :</label>
<input type="text" name="produk_saham" class="form-control">
<br>
<label for="bunga_saham">Bunga :</label>
<input type="text" name="bunga_saham" class="form-control">
<br>
<label for="ket_saham">Keterangan :</label>
<input type="text" name="ket_saham" class="form-control">
</div>
<div class="harian">
<div class="w3-container w3-black">
<h3>
<center>Produk Simpanan Harian</center>
</h3>
</div>
<label for="kp_harian">Kode Produk :</label>
<input type="text" name="kp_harian" class="form-control">
<br>
<label for="produk_harian">Produk :</label>
<input type="text" name="produk_harian" class="form-control">
<br>
<label for="bunga_harian">Bunga :</label>
<input type="text" name="bunga_harian" class="form-control">
<br>
<label for="ket_harian">Keterangan :</label>
<input type="text" name="ket_harian" class="form-control">
</div>
you mush have blueprint of field first like
var blueprint= '<div class="saham">'+
'<div class="w3-container w3-black">'+
'<h3>'+
'<center>Produk Simpanan Saham</center>'+
'</h3>'+
'</div>'+
'<label for="kp_produk">Kode Produk :</label>'+
'<input type="text" name="kp_produk[]" class="form-control">'+
'<br>'+
......
used [] for all name field to get array request when you send form to server
example :
'<input type="text" name="kp_produk[]" class="form-control">'+
and make button add like (jquery) example
<button onclick="$('form').append(blueprint)">add</button>
just use
var dom=$($('.saham')[0]).clone();
//copy dom
$('.form-horizontal').html(dom):
//paste dom
dont forget to add [] on name tag dom input to set data send to array, because if you not set. data with key kp_produk value is last tag name with name kp_produk
if you use [] (kp_product[]) data will set to array
kp_product=['anu1',anu2];
Related
this question has been asked but I haven't found a working solution.
I have 2 forms. The first is sending datas to the database (form2). The second one is uploading a photo (form1).
I would need to save the path of the uploaded picture and store it in a text input in form1 and after send it with the form2 datas. Do you have any tips? It is possible without JQuery using just Php?
I have a solution with JQuery but it is not working.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
function submitform()
{
var name=$('#name').val();
$('#variable').val(name); // set the value of name field to the hidden field
$('form#form1').submit(); // submit the form
}
</script>
Create a new product
<form action="../handlers/processNewProduct.php" id="form2">
<div class="mb-3">
<label for="productname" class="form-label">Product Name</label>
<input type="text" class="form-control" id="productname" name="productname" placeholder="Product Name">
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<input type="text" class="form-control" id="description" value="xxxxxxxxx" name="description" placeholder="Description">
</div>
<div class="mb-3">
<label for="pricelist" class="form-label">Price list</label>
<input type="number" class="form-control" id="pricelist" name="pricelist" placeholder="Price">
</div>
<input type='text' name='variable' id='variable' value=''>
<button type="" class="btn btn-primary">Insert data</button>
</form>
<form action="../handlers/processUploadProductPicture.php" method="post" enctype="multipart/form-data" id="form1" onsubmit="submitform()">
Select image to upload:
<input type='file' name='fileToUpload' id='name'>
<input type='submit' value='Upload Image' id='upload'>
</form>
So, I have my SPA at about 98% functional. The app pulls data from a MySQL database and allows the user to edit/delete records. For the page in question, it will edit/delete data of the specified student ID but it will not properly display the data in the text fields.
If you do not input a value it will display the first item in the JSON array but not the one you specify in the search field.
I did not do a very good job at explaining that but here is the HTML page that uses a function to pass data to the controller which then selects the corresponding student by ID and assigns it to the variable $scope.student. I then try to display the student data on the HTML page by using student.first_name (or any property) but it does not work correctly.
<h3>Edit/Delete Student with ID: {{student.student_id}}</h3>
<div class="form-group">
<label for="sid">Student ID:</label>
<input type="text" class="form-control" id="sid" ng-model="sid">
</div>
<p><button type="button" class="btn btn-primary" ng-click="getRecord(sid)">
Get Student Info </button> </p>
<div class='row'>
<div class="col-md-6">
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" class="form-control" id="first_name" ng-model="student.first_name">
</div>
<div class="form-group">
<label for="last_name">Last Name:</label>
<input type="text" class="form-control" id="last_name" ng-model="student.last_name">
</div>
<div class="form-group">
<label for="hrs_completed">Hrs Completed:</label>
<input type="text" class="form-control" id="hrs_completed" ng-model= "student.hrs_completed">
</div>
<div class="form-group">
<label for="hrs_attempted">Hrs Attempted:</label>
<input type="text" class="form-control" id="hrs_attempted" ng-model= "student.hrs_attempted">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="gpa_points">GPA Points:</label>
<input type="text" class="form-control" id="gpa_points" ng-model= "student.gpa_points">
</div>
<div class="form-group">
<label for="major">Major:</label>
<input type="text" class="form-control" id="major" ng-model="student.major">
</div>
<div class="form-group">
<label for="advisor_id">Advisor ID:</label>
<input type="text" class="form-control" id="advisor_id" ng-model="student.advisor_id">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" class="form-control" id="email" ng-model="student.email">
</div>
</div>
<button type="button" class="btn btn-primary" ng-click="updateRecord()">Update</button>
<button type="button" class="btn btn-primary" ng-click="deleteRecord()">Delete</button>
And here is my controller on my Javascript page:
app.controller('editCtrl', function($scope, $http) {
$http.get("getStudentData.php")
.then(function (response) {
$scope.students = response.data;
});
$scope.getRecord = function(sid) {
id = sid;
$scope.student = $scope.students.find(s=>s.id == sid);
};
Do I need to make a seperate GET request to the server for this to work properly or do I just need to reference the student object differently?
I think there is mismatch in what you are getting as response.data and what you are trying to .find() and then what you are binding on html.
Check this plunkr.
You are trying to render by searching id property.
$scope.students.find(s=>s.id == sid);
where as you are rendering on UI using student_id property.
{{student.student_id}}
So, surely there is mismatch in what you are getting as response.data and what you are rendering using $scope.student properties. I think my plunkr will show that your function is correct.
In case this answer doesn't work, share your response.data.
let's say that I have a form
<form >
<div class="control-group">
<label class="control-label" for="numeinculpat">Nume inculpat</label>
<div class="controls">
<input type="text" id="numeinculpat" placeholder="Nume inculpat" name="nume" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="numeinculpat2">Nume inculpat2</label>
<div class="controls">
<input type="text" id="numeinculpat2" placeholder="Nume inculpat2" name="nume" />
</div>
</div>
</form>
And the user introduce some empty value .
How cand can I do if someone enter wrong data(or empty),when enter again, the input to have the value of data that he previous introduced ??
Add a value attribute and get last value from $_POST like below
<input
type="text"
id="numeinculpat2"
placeholder="Nume inculpat2"
value="<?php echo (isset($_POST['nume']) ? $_POST['nume'] : '' ); ?>"
name="nume"
/>
Input name must be unique, don't use same nume for other input, This might help
You are missing the action and the method attribute of form.
Follow the basic tutorial from here.
http://www.w3schools.com/php/php_form_complete.asp
If you are submitting it to the same page use " method="post">. Now when you submit and if the value is blank or whatever is the problem you will get the last entered value also use this to get the value.
if(isset($_POST["submit"])
{
$text1=$_POST["numeinculpat"];
}
over your html input
<div class="control-group">
<label class="control-label" for="numeinculpat">Nume inculpat</label>
<div class="controls">
<input type="text" id="numeinculpat" placeholder="Nume inculpat" name="nume" value="<?php echo $text1 ?>" />
</div>
</div>
Now when you submit the value you will get the last entered value.
So I am working on a file upload form that seems to lose the information in the file super global from one step to another. So what I do is I print out the file super global before I verify through captcha and then print it out once I validate through the captcha. For some way I lose the information after verifying the captcha. I have tried storing the information in a cookie and a session variable but with no luck. In terms of the cookie direction it saves the file super global information into the cookie only if I hit refresh before captcha validation. In terms of session storage it stores the information in the session variable before I verify the captch but then lose it after I verify the captach. Can you guys people help, and thanks in advance. My code is below:
$DIRECTORY_NAME = "/home/www/xxx/xxxPhotos/";
$FILES = array();
$SPEAKER_STATUS_DROPDOWN = '<option value="">...</option><option value="Suggested">Suggested</option><option value="Invited">Invited</option><option value="Confirmed">Confirmed</option>';
if (empty($_SESSION['captcha']) || strtolower(trim($_REQUEST['captcha'])) != $_SESSION['captcha']) {
$captcha = false;
} else {
$captcha = true;
}
if (!empty($_POST) && $captcha) {
$UNIQ_ID = $_POST['uniq_id'];
$FORM_ID = $_POST['form_id'];
//$uniqid = createuniqid();
// Upload file
if ($_FILES["file"]["name"] != "") {
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
die();
}
else
{
$allowedExtensions = array("jpg","gif","tiff","pdf");
if ($file["file"]['tmp_name'] != '') {
if (!in_array(end(explode(".",
strtolower($file["file"]['name']))),
$allowedExtensions)) {
die($file["file"]['name'].' is an invalid file type!<br/>'.
'<a href="javascript:history.go(-1);">'.
'<< Go Back</a>');
}
}
$filename = "AS_".$uniqid."". strrchr($_FILES["file"]["name"], '.');
move_uploaded_file($_FILES["file"]["tmp_name"],
$DIRECTORY_NAME . $filename);
$filenamequery = ", attachment='$filename' ";
$filenameemailbody = "<br>Attachment: http://www.verney.ca/viewabstract.php?filename=$filename";
}
die('reached here');
}
HTML Form
<form name="frmAbstract" id ="frmAbstract" method="post" action="storiesv.php" onSubmit="return validation();" enctype="multipart/form-data" style="margin-left:20px;">
<input type="hidden" name="uniq_id" value="">
<input type="hidden" name="form_id" value="6">
<div><label class="labelHeader"><strong><h1>Form</h1></strong></label><br/></div>
<div class="formrow">
<label for="question_390">First Name of Submitter: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_390" name="question_390" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_391">Last Name of Submitter: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_391" name="question_391" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_392">Title: </label>
<input type="text" id="question_392" name="question_392" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_393">Organization: </label>
<input type="text" id="question_393" name="question_393" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_394">Phone: </label>
<input type="text" id="question_394" name="question_394" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_395">Email: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_395" name="question_395" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_396">Involvement with the CBS: </label>
<input type="text" id="question_396" name="question_396" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_397">First became a CBS member in (yyyy): <span style="color:#FF0000">*</span></label>
<input type="text" id="question_397" name="question_397" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_398">Your story/experience/anecdote (limit of 250 words): </label>
<textarea name="question_398" name="question_398" style="width:500px;height:200px;"></textarea>
</div>
<div class="formrow" >
<label>Do you have a photo / graphic to upload (scans of print photos are acceptable)? </label>
<div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_399_0" name="question_399[]" value="Yes"><label for="question_399_0">Yes</label></div><div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_399_1" name="question_399[]" value="No"><label for="question_399_1">No</label></div><strong><em></em></strong><div style="clear:both;"></div></div>
<div>
<label for="question_400">Attachment: (Only jpg, gif, tiff, pdf, will be accepted) </label>
<input type="file" id="question_400" name="question_400" style="width:500px;">
</div>
<div class="formrow">
<label for="question_401">For photos submitted, please include names of people in the photo, location, and date. </label>
<textarea name="question_401" name="question_401" style="width:500px;height:200px;"></textarea>
</div>
<div class="formrow" >
<label>Do we have permission to publish this photo in a slide show to be featured at the 2014 CBS Conference and possibly in a printed collection of memoirs intended for past and present CBS members? </label>
<div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_402_0" name="question_402[]" value="Yes"><label for="question_402_0">Yes</label></div><div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_402_1" name="question_402[]" value="No"><label for="question_402_1">No</label></div><strong><em></em></strong><div style="clear:both;"></div></div><div><label class="labelHeader"><strong>Questions</strong></label><br/></div>
<div class="formrow">
<label for="question_404">Tell us about your experience(s) with the CBS. </label>
<input type="text" id="question_404" name="question_404" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_405">How did you become involved in the CBS? </label>
<input type="text" id="question_405" name="question_405" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_406">What is your best memory of the CBS? </label>
<input type="text" id="question_406" name="question_406" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_407">Who have been your role models in the field? </label>
<input type="text" id="question_407" name="question_407" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_408">What has been the most significant accomplishment of Canadian bioethics? </label>
<input type="text" id="question_408" name="question_408" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_409">What is our biggest challenge going forward? </label>
<input type="text" id="question_409" name="question_409" style="width:500px" maxlength="255" value="">
</div>
</fieldset>
<div style="clear:both;"><br><input type="submit" name="btnSave" id="btnSave" value="Next" class="submitbutton" "></div>
<p> </p>
</form>
So the code above is the original code I have been working with. It essentially does the file upload after the captcha is validated, and this is where I lose $_FILES super global
ANSWER: Thanks for all those who viewed my question. The issue was the captcha was in a form on it own page with a enctype set. Therefore the $_FILES super global was overwritten with that forms $_FILES, which of course is not set.
The name of your file input is question_400, so you would need $_FILES["question_400"]["name"], etc.
How can I unset label from a exposed filter in a custom module? (form_alter)
HTML:
...
<form action="/location-list" method="get" id="views-exposed-form-zoekresultaten-geolocation-zoekresultaten" accept-charset="UTF-8">
<div>
<div class="views-exposed-form">
<div class="views-exposed-widgets clearfix">
<div id="edit-distance-wrapper" class="views-exposed-widget views-widget-filter-distance">
<div class="views-widget">
<div class="form-item form-type-textfield form-item-distance-postal-code">
<label for="edit-distance-postal-code">Postcode </label>
<input type="text" id="edit-distance-postal-code" name="distance[postal_code]" value="" size="60" maxlength="16" class="form-text" />
</div>
...
Have you tried to change field using form_alter and set '#title_display' => 'invisible' inside your field?
Form api reference