mardi 31 mars 2015

Form Submission issue Please Help? How I can get value of ID at end of my URL

I have following code and I want to submit my Form on click button, Click function is working fine but tell me how I can Assign values of "ID" at the end of my URL as mentioned on the below code.



<script type="text/javascript">
$(document).ready(function() {
$(".btn-success").click(function(){
var ID = $(this).prev('.sendEmail').attr('id');
alert(ID);
});
});
</script>


<script type="text/javascript">
$(document).ready(function() {
var form = $('#form2'); // contact form
var submit = $('#submit2'); // submit button
var alert = $('.alert'); // alert div for show alert message




// form submit event
form.on('submit', function(e) {
e.preventDefault(); // prevent default form submit

$.ajax({
url: '//mydomain.com/'+ID,
type: 'POST', // form submit method get/post
dataType: 'html', // request type html/json/xml
data: form.serialize(), // serialize form data
beforeSend: function() {
alert.fadeOut();
submit.html('Sending....'); // change submit button text
},
success: function(data) {
alert.html(data).fadeIn(); // fade in response data
form.trigger('reset'); // reset form
submit.html('&#10004; Alert Successfully Sent!'); // reset submit button text
},
error: function(e) {
console.log(e)
}
});
});
});
</script>

Submit with a button who launches Bootstrap Modal

I have a form that i submit with a input type button.



<input class="btn btn-info pull-right" type="submit" value="Post"/><br />


Now id, like to change the submit of my form to a button who also loads the data in a Bootstrap Modal.



<button type="button" class="btn btn-danger" data-toggle="modal" data-target=".bs-example-modal-lg">Post</button>


How do i combine those two?


Configure Parsley using Javascript, not html data attributes

How do I configure Parsley using javascript, not html data attributes?


The documentation examples show how to configure the Parsley form instance and some global field options using JS, but I want to be able to add and configure all field instances that way too. I don't want to use the html data attributes. Is that possible?


I think this question is driving at the same problem, How to use ParsleyJS 2.* using javascript and not data attributes, but it's not 100% clear.


How To Get Value and Set Name From Dynamic Form

Maybe the title made confused. But I have a case like this,


I have a form that contains some input text (textbox). But this input is depend on my database.



<label class="strong"><?php echo $rowexp['mexpense_name']; ?></label>
<input type="text" class="span4" placeholder="Expense <?php echo $rowexp['mexpense_name']; ?>" name="" />


Here's my database for that input text:



tbl_mexpensive -> mexpensive_id, mexpensive_name
tbl_expensive -> expensive id, expensive_year
tbl_texpensive -> mexpensive_id, expensive_id


So the number of textfield will be same as much as the data at tbl_mexpensive and the POST page will set to tbl_texpensive.


For example, if mexpensive got 3 value then: [textbox1] [textbox2] [textbox3] If i click submit It return to POST page and get the value each of the textbox BUT the query is like this: insert into texpensive (exp_id, mexp_id) VALUE (exp_id, XXX)


From above, my question is, how to get the value at the POST page (XXX)? I mean, what name should I give to that input text? I have try an array but it's not work properly. I try give it name as the table value, still no result because it's a dynamic textbox.


Sorry for my bad English.


disable all value of a multiple select when one is selected, then set a null value to the following field

I have a dynamic form using Ajax and javascript on my Symfony project.


I have a multiple select. I would like in this multiple select when I choose the value 7 which is "outside", all other value of this multiple select are disabled and unselectabled.


Here's the code for the scripts:



function checkOption(obj) {
var select = document.getElementById("mySpace_databasebundle_zonestechnique_batiments");
select.disabled = obj.value == "7";
}


And this is the code for the twig view. Just know that I'am using a collection, i-e a formType in my Symfony project for make this form:



<div>
{{ form_label(form.categorieszonestechnique, "Categorie(s) de la zone technique:", {'label_attr': {'class': 'control-label'}}) }}
{{ form_errors(form.categorieszonestechnique) }}
{{ form_widget(form.categorieszonestechnique, {'attr': {'class': 'selectpicker categories', 'onChange': 'checkOption(this)'}}) }}
</div>

<div>
{{ form_label(form.batiments, "Appartenant au bâtiment:", {'label_attr': {'class': 'control-label'}}) }}
{{ form_errors(form.batiments) }}
{{ form_widget(form.batiments, {'attr': {'class': 'form-control', 'option selected': '--choose abâtiment--'}}) }}
</div>


So when I selected the option 7, i-e "outside", I would like to disable all other value of the multiple select (selectpicker) and make them unselectabled. Then make a default value (null value) to the following field for the select tag of "batiments".


The id for the multiple select (selectpicker) is mySpace_databasebundle_zonestechnique_categorieszonestechnique and the id for the select tag of batiments is mySpace_databasebundle_zonestechnique_batiments. So, the javascript code works like with basic html for creating events, but I didn't find yet the solution to create these events.


Thank you in advance.


lundi 30 mars 2015

CodeIgniter from

I have to submit my codeIgniter form which have dynamic columns. how can I get them from controller using a loop.


this is my view page



<?php echo form_open_multipart('main_controller/do_insert');?>
<div id="mainDiv">
<div><input type="text" name="name0"/></div>
<div><input type="file" name="img0"/></div>
</div>
<input type="button" value="add an entry" onClick="add('0')">
<input type="submit" value="save all"/>
<?php from_close();?>

<script>
function add(x)
{
var count=x;count++;
var str1="<div><input type='text' name='name"+count+"'/></div>"
var str2="<div><input type='file' name='img"+count+"'/></div>"
var str3="<input type='button' value='add an entry' onClick='add(`1`)'>";
$("#mainDiv").append(str1+str2+str3);
}
</script>


note: the value of 'x' may not work properly but its not relevant here, can fix it by a global variable.


My problem is that how can i code controller for getting all the values including images and save them to table, while submitting the form.


Inserted data using phpmyadmin and one column keeps repeating the value of the first test case that i tried

my php script is like:



$mobnumber = mysqli_real_escape_string($conn, $_POST["mobnumber"]);
$name = mysqli_real_escape_string($conn, $_POST["name"]);
$state = mysqli_real_escape_string($conn, $_POST["state"]);
$role = mysqli_real_escape_string($conn, $_POST["role"]);
$designation = mysqli_real_escape_string($conn, $_POST["designation"]);
$organisation = mysqli_real_escape_string($conn, $_POST["organisation"]);
$mail = mysqli_real_escape_string($conn, $_POST["mail"]);
$addr = mysqli_real_escape_string($conn, $_POST["addr1"].", ".$_POST["addr2"].", ".$_POST["addr3"].", ".$_POST["addr4"].", ".$_POST["addr5"]);
$sql="INSERT INTO admin_reg VALUES (null, '$mobnumber', '$name', '$state', '$role', '$designation', '$organisation', '$mail', '$addr')";


my form space for the mobnumber field is:



<label class="description" for="mobnumber">Contact Number </label>
<div>
<input id="mobnumber" name="mobnumber" class="element text medium" type="text" maxlength="255" value=""/>
</div>


No matter what value i enter in the mobile number field, im getting it as the random mobile number of the first test case.