/    Sign up×
Community /Pin to ProfileBookmark

Re-display of multi-line form ?? please help !

Hello ?
I am trying to validate the form and then if it fails, to re-display
the form with previous details so that the correct data is not lost.

The problem is that I need to increment $so_dat and $so_num
with $i , but I don’t know how to ? Or do I need a total re-write ?

ALSO when $so_num == ‘same’ I want it to be egual to the date that
was entered in the preceeding date – this saves re-typing the date each
time.

This is the process part called a_test.php

php

$a=1;

if(isset($_POST[‘sal_fm’])) { // BIG IF Means they filled in the form

for($i = 0; $i < 5; $i++){

$so_dat = strip_tags(trim($_POST[“so_dat$i”]));
$so_num = strip_tags(trim($_
POST[“so_num$i”]));

if($so_dat != ‘same’){
if(!ereg(“^[0-9]{2}[0-9]{2}[0-9]{4}$”,$so_dat)){
$mess = “yes”;
$message1 = “Available date format must be dd-mm-yyyy”;
$message2 = “Please re-enter”;
require_once (“a_test_fm.php”);
exit();
} // endif
} // endif
else{
$j = $i-1;
$so_dat = strip_tags(trim($_POST[“so_dat$j”]));
/*
*
Update database and exit
*
*
/
// update db

} // end else
} // end loop

} // end if END BIG IF

$today = date(U);
$so_dat = date(“d-m-Y”,$today);

require_once (“a_test_fm.php”);

AND HERE IS THE FORM ( CALLED a_test_fm.php )

<?php
if ($mess == “yes”) {
echo”
<div class = ‘head’ style=’position:absolute;left:130px; top:0px; font-size:16px;’>
<p><font color=’red’><b>ERROR: $message1<BR>$message2</b></font></p>
</div> “;
} // endif
?>

<div style=’position:absolute;left:200px; top:100px;’ >
<form action =’a_test.php’method = ‘POST’>
<input type=”hidden” name=”sal_fm” value=”yes” />

<table style=”width:150px; table-layout:fixed;” border = ‘0’ cellspacing = ‘2’ >
<?php
for($i=0;$i<5;$i++){

if($i >= 1){
$so_dat = “same”;

} // end if

echo ”
<tr>
<td><input type=’TEXT’ name=’so_dat$i’ value = ‘$so_dat’
size = ’10’ maxlength=’10’/></td>

<td><input type=’TEXT’ name=’so_num$i’ value = ‘$so_num’
size = ‘6’ maxlength=’10’/></td>
</tr>”;
} // end loop
?>
<tr>
<td ><input type=”submit” class=”btn_long” name = “batch” value = “Next Order”
onMouseover=”this.style.backgroundColor=’red'”
onMouseout=”this.style.backgroundColor=’yellow'” ></td>
</tr>

</table>
</form>
</div>

PLEASE HELP ME GET THIS WORKING – THANK YOU.
David

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsApr 25.2005 — example:[code=php]<input type="text" id="foo" name="foo" value="<?php echo (is_array($_POST)) ? $_POST['foo'] : 'default value'; ?>">[/code]
Copy linkTweet thisAlerts:
@DaveinLondonauthorApr 26.2005 — This looks like something I could use, but I have never seen anything

like: <input type="text" id="foo" name="foo" value="<?php echo (is_array($_POST)) ? $_POST['foo'] : 'default value'; ?>">

especially the

<?php echo (is_array($_POST)) ? $_POST['foo'] : 'default value'; ?> part.

I dont understand the " ? " is this picking up 'foo' from the previously POSTed

form ? ?

If so I would need to initailise the first 'foo' would I ?

I have posted a new post under - "Can I simplify this and speed it up"

This post shows more cleary what I am trying to do - can you please help me to implement what you are suggesting into that code.


Thanks

david.
Copy linkTweet thisAlerts:
@ShrineDesignsApr 26.2005 — the (expression) ? statement : statement; is a short hand form of an if/else statement

yes, exactly
Copy linkTweet thisAlerts:
@DaveinLondonauthorApr 26.2005 — Thanks

Any chance of taking a peek at the other thread to see how I can implement you

very nice way of coding ??

Thanks
×

Success!

Help @DaveinLondon 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,
)...