...

View Full Version : How to get value from this form?



pavelazad
01-07-2008, 09:02 PM
hello
i have a appending form. please help me and show me how to get the user input value from the given form using PHP:

<html>

<head>

<title>Title</title>

<meta content="">

<style></style>



<script language="javascript">





var counter = 0; // counter for naming the elements



function moreFields()

{

counter++;

var newFields = document.getElementById('readroot').cloneNode(true);

newFields.id = '';

newFields.style.display = 'block';

var newField = newFields.childNodes;

for (var i=0;i<newField.length;i++)

{

var theName = newField[i].name

if(theName)

{

newField[i].name = theName + counter;
newField[i].id = theName + counter;
}

}

var insertHere = document.getElementById('writeroot');

insertHere.parentNode.insertBefore(newFields,insertHere);

}



// -->

</script>



</head>

<body onload="moreFields()">



<div id="readroot" style="display: none">
<div align="center">Job Experience <br>
Company:
<input type="text" name="company" size="70">
<br>
Post :
<input type="text" name="post" size="70">
<br>
Job Duties:
<textarea name="duties" cols="60" rows="10"></textarea>
<input type="button" value="Remove" style="font-size: 10px" onClick="this.parentNode.parentNode.removeChild(this.parentNode);">
</div>
</div>



<form method=post>



<span id="writeroot"></span>

<p class="hr">&nbsp;</p>



<input type="button" value="Add New Line" onClick="moreFields()"><br>

<input type="submit" value="Send form">



</form>





</body>

</html>

Iszak
01-07-2008, 10:38 PM
What you'll do is set the name of company and post to this



<input type="text" name="company[]" size="70">
<input type="text" name="post[]" size="70">


And that'll make an array in a number order starting from 0.
so to use that you would do something like this



<?php
extract($_POST);

print_r($company);
print_r($post);

// OR
foreach ($company as $input)
{
// DO THIS
}
?>

fl00d
01-07-2008, 10:41 PM
$_POST (http://www.php.net/variables.external)

It's also good practice to specify what script the form is supposed to use.

<form action="scriptName.php" method="post">

pavelazad
01-09-2008, 08:12 PM
Thanx for ur help. pls help me abit more..

i added two more fields which wont expand. i m unable to get value from that field. im giving u the code of the form below:

<html>

<head>

<title>title</title>

<meta content="">

<style></style>



<script language="javascript">





var counter = 0; // counter for naming the elements



function moreFields()

{

counter++;

var newFields = document.getElementById('readroot').cloneNode(true);

newFields.id = '';

newFields.style.display = 'block';

var newField = newFields.childNodes;

for (var i=0;i<newField.length;i++)

{

var theName = newField[i].name

if(theName)

{

newField[i].name = theName + counter;

newField[i].id = theName + counter;

}

}

var insertHere = document.getElementById('writeroot');

insertHere.parentNode.insertBefore(newFields,insertHere);

}



// -->

</script>



</head>

<body onload="moreFields()">



<div id="readroot" style="display: none">
<div align="center">Job Experience <br>
Company:
<input type="text" name="company[]" size="70">
<br>
Post :
<input type="text" name="post[]" size="70">
<br>
Job Duties:
<textarea name="duties[]" cols="60" rows="10"></textarea>
<input type="button" value="Add New Line" onClick="moreFields()">
<input type="button" value="Remove" style="font-size: 10px" onClick="this.parentNode.parentNode.removeChild(this.parentNode);">
</div>
</div>



<form method="post" action="test1.php">
Name:<input type="text" name="name" size="70"><br>
Address:<input type="text" name="name" size="70">



<span id="writeroot"></span>

<p class="hr">&nbsp;</p>




<input type="submit" value="Send form">



</form>





</body>

</html>

Also im facing problem to insert all the data into mysql. Mysql TABLE field are
ID, NAME, ADDRESS, COMPANY, POST, DUTIES, DATE. how can i insert data in a single row? please help me.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum