php fill out fields when submit?
5 posts
Page 1 of 1
Hello friends,
seems this don't work
who can help me out?
the message keep saying 'You must fill out ALL fields.'
seems this don't work
who can help me out?
the message keep saying 'You must fill out ALL fields.'
Code: Select all
100 CC for the one who helpme to get this to works <?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);
}
?>
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
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
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.
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.
hello #mandai,
can you give the right example to make this work please
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
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
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);
}
?>
:lol: Solved
works like a charm.
thanks m8
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
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
Copyright Information
Copyright © Codenstuff.com 2020 - 2023