update form structure using ajax [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Recently i have been working over a contact module.There are 3 columns ie. name, email, phone and a +1 button which includes anew row to add one more contact filed using ajax.
And here the problem arise. When i update my structure, the data in old contact field vanishes.
Eg:
I entered 2 rows and filled the data as name1, email1, and so on..
name1 email1 phone1
name2 email2 phone2
Now in order to add one more contact filed i use +1 botton. and as soon i click it i get:
blank_1 blank_1 blank_1
blank_2 blank_2 blank_2
blank_3 blank_3 blank_3 //here blank_1, blank_2, blank_3 are just expressing blank columns
My jquery code is :
$(document).ready(function(e) {
num = 0;
$('#plus_contact').click(function(e) {
num = num +1 ;
$.ajax({
url : 'contact/contact_form.php',
method : 'POST',
data : "number="+num,
success : function(data) {
$('#contact_form_div').html(data);
},
});
});
});
contact_form.php
<?php
if(isset($_POST['number']) && is_numeric($_POST['number']))
{
echo $list =$_POST['number'];
if($list == 1)
{
for($i=0; $i<$list;$i++)
{
?>
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Full Name</label>
<input type="text" name="c_name[]" class="form-control" id="c_full_name" placeholder="Full Name">
</div>
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Email address</label>
<input type="email" name="c_email[]" class="form-control" id="c_email_id" placeholder="Email">
</div>
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Phone</label>
<input type="tel" name="c_phone[]" class="form-control" id="c_phone_number" placeholder="Phone">
</div>
<?php
}
} } ?>
How can i add a row without altering the old row data ??

Since nobody cares to even point Rahul in the right direction, I will provide atleast something.
There have been several projects to allow PHP to be used for desktop application development.
http://gtk.php.net/
http://wxphp.org/
So natively, no PHP can't be used for desktop application development, but that doesn't mean there is no way to do it.
Zend actually posted an article about it: http://devzone.zend.com/1129/developing-desktop-applications-in-php-for-beginners/
Hope this helps..

Related

Editable text in Laravel [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I need to make a text that can be edited by user but in some parts I need to make static text for example the date and ....,how to make it ,plz can anyone help me
I have tried the normal input but it did not work as I expected
you can define editable part in page for each section, after type in input with js concatenation all text in main input, and in submit just pass main text to back-end.
like bellow:
<input type="hidden" name="text" id="main-text-id">
<input class="text-part" type="text">
<input class="text-part" type="text">
<input class="text-part" type="hidden"> <!--static part-->
<input class="text-part" type="text">
<input class="text-part" type="hidden"> <!--static part-->
...
and your script :
<script>
const mainText = document.getElementById('main-text-id');
const inputs = document.querySelectorAll('.text-part');
inputs.forEach(input => {
input.addEventListener('input', () => {
mainText.value = Array.from(inputs).map(input => input.value).join(' ');
});
});
</script>

<label> element with input inside - hot to get text and input value at the same time? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a bit of a problem. I have element with form::input in it. And i want to get lebel text and input value at the same time and pass it to another element as value.
For ex.
<label for="contact">Only contact if the fee is over <input id="jpy" min="0" name="JPY" type="number" value=""> JPY(Include tax)
</label>
What i want to achieve is to pass "Only contact if the fee is over 1000 JPY(Include tax)" as a value to another element.
I know how to get .text() of label element and i know how to get value from input. But i don't know how to get them at the same time in consistent form.
You can use .contents(), but a better approach would be to use label tag correctly:
$('button').on('click', () => {
let contents = $('label').contents()
console.log(contents[0].wholeText + $(contents[1]).val() + contents[2].wholeText)
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label for="contact">Only contact if the fee is over <input id="jpy" min="0" name="JPY" type="number" value=""> JPY(Include tax)
</label>
<button id="button">Get text</button>
$('button').on('click', () => {
var label = $('label[for="contact"]').text();
var input = $('#jpy').val();
console.log(label+' '+input);
});
Hope this works

Form input submit to table with this data [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Helou,
I have a form like this
<form id="some" data-request="checkout" class="checkoutForm">
<div class="form-group mb10">
<label for="firstName" class="col-sm-12">Name <span class="color-main">*</span></label>
<input class="form-control checkout-form-border" id="firstName" value="" type="text">
</div>
<div class="form-group mb10">
<label for="Address" class="col-sm-12">Address <span class="color-main">*</span></label>
<input class="form-control checkout-form-border" id="address" value="" type="text">
</div>
etc etc ....
</form>
Now, I want on submit button show new page with collected data from this form in a table body.
Can I do this via php and jquery or new custom component?
Thanx
PHP:
need a submit button in the form
need action=" " and method="post" attributes added to your form tag
need to add name attributes to your input boxes
Top of page,
if(isset($_POST['submit'])){
$variable = $_POST['namedOfInputBox'];
echo "<table><tr><td>$variable</td></tr></table>";
{
What that says is if the form is submitted (submit being name of your submit button, generally name it submit), the values coming through are these and in PHP we "echo", or print, out html code and place our variable here. You can either use :
echo "<table><tr><td>$variable</td></tr></table>";
or
echo "<table><tr><td>" . $variable . "</td></tr></table>";

HTML/PHP Forms? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need help with creating a form. It can be on blank page, I just need forms on a page.
example : NAME _______
And I would like the filled form be stored on the server so I can print them.
Print example: NAME firstname lastname
Thanks in advance!
Let's say we have two files. The first file, called index.html is a pure-HTML page that displays a form. The second file is called process.php which handles the data from the form server-side.
index.html:
<!DOCTYPE html>
<html>
<head>
<title>Example Form</title>
</head>
<body>
<form action="process.php" method="POST">
<label for="firstname_input">First Name:</label><br>
<input type="text" id="firstname_input" name="firstname" /><br>
<label for="lastname_input">Last Name:</label><br>
<input type="text" id="lastname_input" name="lastname" /><br>
</form>
<input type="submit" value="Submit" />
</body>
</html>
process.php:
<?php
if (!isset($_POST['firstname']) || !isset($_POST['lastname']))
{
die("Error! Both the firstname and lastname must be specified.")
}
$firstName = $_POST['firstname'];
$lastName = $_POST['lastname'];
echo sprintf("You specified a first name of '%s' and a last name of '%s'.", htmlspecialchars($firstName), htmlspecialchars($lastName));
From here, you can store $firstName and $lastName in a file or a database (such as MySQL) to store them permanently, but that seems to be beyond the scope of the question. If you choose to store them in MySQL, something like this should work:
$sql = $db->prepare("INSERT INTO user (first_name, last_name) VALUES (:first_name, :last_name)");
$sql->bindValue(':first_name', $firstName);
$sql->bindValue(':last_name', $lastName);
if (!$sql->execute())
{
die("Failed to add user to database.");
}
You didn't specify how or where you wanted to store the data, and there are many other ways to store it, but this is how you'd do it in MySQL.
Here is the code for it :
<form>
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
For getting that values in next page u can use ,
action = POST
this parameter in form tag.

How to validate date of birth that should be less than 18 years old in Codeigneter [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I used so many stuff but I am unable to validate date of birth should be less than 18 years old
<?php echo form_error('DOB'); ?>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Date Of Birth
</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="datepicker" name="DOB" placeholder="Date Of Birth" value="<?php echo set_value('DOB'); ?>" >
Alternatively, you could use a callback for this. Example:
public function your_form_page()
{
$this->load->library('form_validation');
// this part is when you set your validation rules
$this->form_validation->set_rules('DOM', 'Date of Birth', 'trim|required||callback_validate_age');
$this->form_validation->set_message('validate_age','Member is not valid!');
}
// you need to add this on the controller, this will be the custom validation
public function validate_age($age) {
$dob = new DateTime($age);
$now = new DateTime();
return ($now->diff($dob)->y > 18) ? false : true;
}

Categories