Hello I work with WordPress , and I create a custom Modal with form to add a Group called 'abonnement' I added the table in Database and this is my issue:
Form
<form name="abonnementCreate" action="create.php" method="POST">
<div class="form-group">
<label>Nom de l'abonnemnt</label>
<input type="text" class="form-control" id="nomA" name="nomA">
</div>
<div class="form-group">
<label>Durée</label>
<input type="number" class="form-control" id="dureeA">
<small id="dureeHelp" class="form-text text-muted">En jours</small>
</div>
<div class="form-group">
<label>Nombre de produit autorisé</label>
<input type="number" class="form-control" id="nbProdA">
</div>
<div class="form-group">
<label>Frais d'abonnement (€)</label>
<input type="number" class="form-control" id="fraisA">
</div>
<button type="submit" name="create" class="btn btn-primary">Valider</button>
</form>
and this is the action of the creation :
create.php
<?php
include'admin.php';
global $wpdb;
if(isset( $_POST["create"]))
{
$wpdb->insert('abonnement', array(
'nom' => '.$_POST["nomA"].',
'duree' => '.$_POST["dureeA"].',
'nbProd' => '.$_POST["nbProdA"].',
'frais' => '.$_POST["fraisA"].'
));
}
?>
I have $_POST["create"] and the condition is true but $_POST[" any field"] is always null,
Someone please can help me ?
you can never catch the post value from id of the form input field.only way that you can get value using $_POST[] is using the "name" attribute of the input field.
<input type="text" class="form-control" id="nomA" name="name1">
this input field value can be accessed from form action php file using $_POST["name1"]
Related
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];
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.
I'm using symfony 2.8, I'm submitting a registration from to registerAction method. I'm getting all my submitted data like this when I use $form-getdata() in registerAction method.
AppBundle\Entity\User Object
(
[id:AppBundle\Entity\User:private] =>
[name:AppBundle\Entity\User:private] => testname
[email:AppBundle\Entity\User:private] => test#test.com
[roles:AppBundle\Entity\User:private] => Admin User
[plainPassword:AppBundle\Entity\User:private] => 123456
[password:AppBundle\Entity\User:private] =>
)
I have used $request->request->get('name') to get single name value but it is showing blank screen and printing nothing.
My html form looks like this on viewing source code in browser.
<form name="user" method="post" novalidate="novalidate">
<div class="form-group">
<div><label for="user_name" class="required">Name</label><input type="text" id="user_name" name="user[name]" required="required" class="form-control" /></div>
</div>
<div class="form-group">
<div><label for="user_email" class="required">Email</label><input type="email" id="user_email" name="user[email]" required="required" class="form-control" /></div>
</div>
<div class="form-group">
<div><label for="user_roles" class="required">Roles</label><select id="user_roles" name="user[roles]" class="form-control" style="margin:5px 0;"><option value="Normal User">Normal User</option><option value="Admin User">Admin User</option></select></div>
</div>
<div class="form-group">
<div><label for="user_plainPassword_first" class="required">Password</label><input type="password" id="user_plainPassword_first" name="user[plainPassword][first]" required="required" class="form-control" /></div>
</div>
<div class="form-group">
<div><label for="user_plainPassword_second" class="required">Repeat Password</label><input type="password" id="user_plainPassword_second" name="user[plainPassword][second]" required="required" class="form-control" /></div>
</div>
<div><button type="submit" id="user_Register" name="user[Register]" class="btn btn-success form-control">Register</button></div><input type="hidden" id="user__token" name="user[_token]" value="epZFHVctxHFlsnxG-H4OdS92DmGVjP1DDF-bKJrV2Ss" />
</form>
How can I get single posted form value.?
If $request->request->get('{form_name}') returns an array with your form data, then you can access the specific input field with $request->request->get('user')['name']. But you should use form classes instead, where you can define all of necessary fields with validation constraints, etc. Hope this helps!
here is my html
<form name="station" method="post" action="/stations/new" role="form">
<div class="form-group">
<label class="control-label required" for="station_name">Name</label>
<input type="text" id="station_name" name="station[name]" required="required" maxlength="255" class="form-control" >
</div>
<div class="form-group">
<div class="checkbox">
<label for="station_active">
<input type="checkbox" id="station_active" name="station[active]" value="1" />Active</label>
</div>
</div>
<div class="form-group">
<button type="submit" id="station_submit" name="station[submit]" class="btn btn-primary">Ajouter</button>
</div>
<input type="hidden" id="station__token" name="station[_token]" class="form-control" value="aze123aze" >
</form>
i want to get my form using the crawler. I tried the selectButton method like this
$form = $crawler->selectButton('station[submit]')->form(array());
but i get the error : InvalidArgumentException: The current node list is empty.
what is the problem ?
Unfortunately I have no enough rating to just write a comment instead of put it in the answer.
So, could you please show how are you getting $crawler? Problem might be:
$crawler not point to DOM which contains this form
this form appears on page after some java script actions(Ajax for example), but not sure that this is your case.
The selectButton method accept the value The button text. So Try with:
$form = $crawler->selectButton('Ajouter')->form(array());
Hope this help
I have the file "1.php" and the file "2.php" ...
In "1.php", there's a HTML form:
<form action="2.php" method="post">
<div class="form-group">
<label for="db_username">Field 1:</label>
<input type="text" class="form-control" id="db_username">
</div>
<div class="form-group">
<label for="db_password">Field 2:</label>
<input type="password" class="form-control" id="db_password">
</div>
<div class="form-group">
<label for="db_passphrase">Field 3:</label>
<input type="text" class="form-control" id="db_passphrase">
</div>
<button type="submit" class="btn btn-default">Next</button>
</form>
While in "2.php", the action must be applied in PHP .. like that:
<?php
// Process of Step "1"
$db_username = $_POST['db_username'];
$db_password = $_POST['db_password'];
$db_passphrase = $_POST['db_passphrase'];
if( !isset($db_username) || !isset($db_password) || !isset($db_passphrase) ) {
header("Location: 1.php?error=1");
die();
}
?>
However .. the values of $_POST['db_username'], $_POST['db_password'] and $_POST['db_passphrase'] is empty...
You need to use the name attribute to later access the $_POST data, as in:
<input type="text" class="form-control" id="db_username" name="db_username">
You need to give the inputs a name and acces that value through $_POST['name'].
id is not relevant for php form handling
You have to give name for the textfields like this
<input type="text" class="form-control" id="db_username" name="db_username">
Put name instead of id. it should work