Forum Moderators: coopster

Message Too Old, No Replies

Drop Down Option Value Authentication

Drop Down Option Value Authentication

         

ecnaralc

1:52 am on Oct 9, 2009 (gmt 0)

10+ Year Member



Hi Guys.
I have a drop down box, which if the user forgets to select a category from I want an error message to say they need to select a category, at the moment a 0 is automatically inserted on form submit. Below is the code.
I am not certain how to go about this, anyone have any ideas.
Thanks in advance
Wayne.

<select name="section" id="section">
<option value="0">Select Section</option>
<?PHP
// Generate a drop-down list of sections.
$result = $connector->query('SELECT ID,name FROM cmssections ORDER BY name');
// Get an array containing the results.
// Loop for each item in that array
while ($row = $connector->fetchArray($result)){
echo '<option value="'. $row['ID'].'ttt11ttt'.$row['name'].'">'.$row['name'].'</option>';
}
?>
</select>

skinsey

11:22 am on Oct 15, 2009 (gmt 0)

10+ Year Member



Should be $_POST if you didn't catch that error. Anyway, time to crash good luck.

ecnaralc

11:24 am on Oct 15, 2009 (gmt 0)

10+ Year Member



Hi skinsey, got the below error.
Parse error: syntax error, unexpected '&' in <textarea name="content" cols="115" rows="35" class="box" id="content" value="<?php echo &_POST['content'] ?>"</textarea>
I changed the '&' to '$' but everything bounced from the bottom of the page into the content area again.

TheMadScientist

11:29 am on Oct 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You're missing a > on the code above, and you're not getting the value, because on a textarea you set the value between the tags, not as value="".

In HTML:
<textarea name="content" cols="115" rows="35" class="box" id="content">Value Goes Here</textarea>

To echo the PHP value:
<textarea name="content" cols="115" rows="35" class="box" id="content"><?php echo $_POST['content'] ?></textarea>

skinsey

11:36 am on Oct 15, 2009 (gmt 0)

10+ Year Member



<textarea name="content" cols="115" rows="35" class="box" id="content" value="<?php echo &_POST['content']; ?>"</textarea>

If forgot a semicolon not sure if that is what is causing the problem. I will recreate it here to see if I get the same problem.

skinsey

11:50 am on Oct 15, 2009 (gmt 0)

10+ Year Member



ok found the problem after testing

<textarea name="content" cols="115" rows="35" class="box" id="content" value="<?php echo $_POST['content']; ?>"></textarea>

it was missing ">" after the value

ecnaralc

1:10 am on Oct 16, 2009 (gmt 0)

10+ Year Member



Okay guys. Thanks for yur help. It all works now.
I used the below code from TheMadScientist. But I had to insert a a semi colon before ?> at end of statement.
Thanks very much for your perserverence. The form does not clean itself after posting but thats fine.

<textarea name="content" cols="115" rows="35" class="box" id="content"><?php echo $_POST['content'] ?></textarea>

TheMadScientist

2:17 am on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you are POST[''] to keep the values filled in you can simply check to see if the submission was successful then unset($_POST); and it will clear.

if($successfulEntry=="Yes) {
unset($_POST);
}

// RE: Added ; - That's what happens when I switch back and forth between styles... Shorthand <?= ?> does not require one, but <?php echo ?> does. I'm not always very good at double checking here. ;)

This 37 message thread spans 2 pages: 37