php fill out fields when submit?

5 posts Page 1 of 1
Contributors
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

php fill out fields when submit?
Dummy1912
Hello friends,
seems this don't work
who can help me out?

the message keep saying 'You must fill out ALL fields.'
Code: Select all
<?php
function display_form($data, $message='') {
if(!empty($message)) {
echo "<p>$message</p>";
}
?>
<form  method="post">
<table width="689" style="text-align: left;">
 
<tr><td>Comment: </td><td><textarea name="comment" cols="75" style="max-width: 330px;" value="<?php echo $_POST['comment']; ?>" /></textarea></td></tr>
 
<tr><td>Company: </td><td><input type="text" size=50 name="company" value="<?php echo $_POST['company']; ?>" /></td></tr>

<tr><td>Comment By: </td><td><input type="text" size=40 name="comment_by" value="<?php echo $_POST['commentby']; ?>" /></td></tr>
<tr><td></td><td><input type="submit" value="Submit" /></td></tr>
</table>
</form>
<?php

}

if(empty($_POST)) {
display_form($_POST);

} else if(!$_POST['comment'] || !$_POST['commentby'] || !$_POST['company']) {
$message = "You must fill out ALL fields.";
display_form($_POST, $message);

} else {
//here we send them to the action page but for now testing we show this message.
// but this don't come  cryer; 
$message = "Thank you.";
display_form($_POST, $message);

}
    ?>

100 CC for the one who helpme to get this to works :)
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: php fill out fields when submit?
mandai
I can see there are some issues with that code.

The reason you are getting that message is because the commentby variable is not sent, it looks like you have named it comment_by.

Also the textarea element does not have a value attribute, so it won't display anything after the form has been submitted.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

hello #mandai,

can you give the right example to make this work please :)
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: php fill out fields when submit?
mandai
Ideally you should use this code:
Code: Select all
<?php
function display_form($data, $message='')
{
	if(!empty($message))
	{
		echo "<p>$message</p>";
	}
}
?>
<form method="post">
<table width="689" style="text-align: left;">

<tr><td>Comment: </td><td><textarea name="comment" cols="75" style="max-width: 330px;" /><?php echo $_POST['comment']; ?></textarea></td></tr>

<tr><td>Company: </td><td><input type="text" size="50" name="company" value="<?php echo $_POST['company']; ?>" /></td></tr>

<tr><td>Comment By: </td><td><input type="text" size="40" name="commentby" value="<?php echo $_POST['commentby']; ?>" /></td></tr>
<tr><td></td><td><input type="submit" value="Submit" /></td></tr>
</table>
</form>
<?php

if(empty($_POST))
{
	display_form($_POST);

}
else if(!$_POST['comment'] || !$_POST['commentby'] || !$_POST['company'])
{
	$message = "You must fill out ALL fields.";
	display_form($_POST, $message);
}
else
{

	//here we send them to the action page but for now testing we show this message.
	// but this don't come  cryer;
	$message = "Thank you.";
	display_form($_POST, $message);

}

?>
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

:lol: Solved

works like a charm.

thanks m8
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
5 posts Page 1 of 1
Return to “Help & Support”