/    Sign up×
Community /Pin to ProfileBookmark

help with html and php

<select name=date>
<?php
$now = time();
for($day=0; $day < 5; $day++)
echo “<option>”.date(“l j F”, $now + ($day * 24*60*60)).”</option>n”;
?>
<select>

I have a form.html which contains 2 text fields and select list like the above one and this called in .php file where i want to check the input entered by the user and if user input is wrong i want to precomplete the good fields indicating the incorrect ones empty and as well as i want to show my selected days back to if one of the input is wrong

can i know how to precomplete the good fields indicating the incorrect ones empty and as well as i want to show my selected days back to if one of the input is wrong and how to check the date is valid or not

Thanks for help

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsApr 15.2005 — example[code=php]<?php
$error = array();
$post = array();

if($_POST)
{
while(list($k, $v) = each($_POST))
{
if(empty)
{
$error[] = "$k is empty!";
}
$post[$k] = (!get_magic_quotes_gpc()) ? addslashes($v) : $v;
}
if(empty($error))
{
// no errors, process form data ...
}
else
{
$errors = implode('<br />', $error);
}
}
?>
<html>
<head>
<title></title>
</head>
<body>
<?php
if(isset($errors))
{
echo $errors;
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div>textbox: <input type="text" name="textbox" id="textbox" value="<?php echo (!empty($post)) ? $post['textbox'] : ''; ?>"></div>
<div>select: <select id="select" name="select">
<?php for($d = 0; $d < 5; $d++){
$date = date('l j F', mktime(0, 0, 0) + ($d * 24 * 60 * 60)); ?>
<option <?php echo (!empty($post) && $post['select'] == $date) ? 'selected' : ''; ?>><?php echo $date; ?></option>
<?php?>
</select></div>
<div><input type="submit" name="s" id="s" value="Submit"></div>
</form>
</body>
</html>[/code]
×

Success!

Help @win006 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...