Hi. Tried to post this a bit ago and not sure where the post ended up ... haha
Anyway, I'm a newbie here. I learned PHP a while back but haven't used it in a while now. However, even when I was working with it before, I'm not sure I ever needed to put PHP within a form that was already in a PHP program... Like what I'm doing right now.
The RED code below inserts a "drop down" for country codes into the html form. Within each "option" tag for this country drop down, I want a bit of PHP too - and that is to just test to see if a value had been entered before we went off to edit the submitted values...and if so, I'll retain that user's entered value when the screen is displayed again (it's displayed again so they can correct whatever errors may end up getting pointed out via edits).
This is very rough right now. It doesn't even have any real edits in it (I make each 'submit' fail as if there were edit issues for now).
I want to focus on the RED code here. So that the code inserted within the country drop-down 'option' statements is really recognized as code and really does the test it should be doing. I'm hoping that is clear.
Anyway, your assistance is GREATLY appreciated!
MOD EDIT: Removed [noparse][color] bbcode tag and inserted code comment (" HERE ") at the corresponding location.[/noparse]
<?php
$Mobile = $_POST["Mobile"];
$Carrier = $_POST["Carrier"];
$Country = $_POST["Country"];
top:
if (!isset($_POST['submit'])) { // if not yet submitted then display the main form
?>
<html>
<head>
<title>title stuff</title>
</head>
<body bgcolor="#203302" text="#0EEFFF" link="#FFFFFF" vlink="#CCCCCC" alink="#33FFFF">
<div id="Layer1" style="position:absolute; z-index:3; left: 17%; top: 20%;">
<form method="post" action="<?php echo $PHP_SELF;?>" onReset="return confirm('Do you really want to reset the form?')"
MOBILE#:<input type="text" size="10" maxlength="10" name="Mobile" value="<?php echo $savemobl;?>">
CARRIER:<select name="Carrier">
<option value="" <?php if ($savecarr == '') print 'selected'; ?>> </option>
<option value="ATT" <?php if ($savecarr == 'ATT') print 'selected'; ?>>AT&T</option>
<option value="Sprint" <?php if ($savecarr == 'Sprint') print 'selected'; ?>>Sprint</option>
<option value="TMobile" <?php if ($savecarr == 'TMobile') print 'selected'; ?>>TMobile</option>
<option value="Verizon" <?php if ($savecarr == 'Verizon') print 'selected'; ?>>Verizon</option></select>
<?
$htmlco = 'COUNTRY:<select name=\"Country\">';
$myFile = 'countries.txt';
$fh = fopen($myFile, "r");
while(! feof($fh))
{
$theData = fgets($fh);
$piece = explode(",", $theData);
/** HERE **/ $htmlco = $htmlco.'<option value ="'.$piece[0].'"'.' <?php if ($savecou=="'.$piece[0].'") print "selected"; ?> >'.$piece[0].'</option>';
}
fclose($fh);
$htmlco = $htmlco.'</select><br />';
echo $htmlco;
?>
<input type="submit" value="Update Now!" name="submit">
<INPUT TYPE=RESET VALUE="Cancel">
</form>
</div>
<?
} else {
$e = '';
if (editpers($e) != '') {
?>
<html>
<head>
<title></title>
</head>
<body>
<form method=get action="whereveryouwant.com" onSubmit="return false;">
(EXPERIMENTING ONLY HERE - EDITS FORCED TO FAIL) THERE IS A PROBLEM WITH YOUR INFO<br />
<input type="submit">
</form>
<?
$savemobl = $Mobile;
$savecarr = $Carrier;
$savecou = $Country;
unset($_POST['submit']);
goto top;
}
else {
echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";
foreach ($genre as $g) { echo $g."<br />"; }
echo "<i>".$quote."</i><br />";
}
}
?>
<?php
function editpers($epmsg)
{
$epmsg = 'state field is incorrect, please try again';
return $epmsg;
}
?>