Jump to content

Recommended Posts

Hello all,

I have a php form for a school program that teachers use to apply to teach in the program.  During the application process, the applicant is asked to designate their specialty.  For this, they can check up to two checkboxes for their specialty (i.e. biology, chemistry or geology,volcanology). 

Later on, I have an 'Edit Details' page where the applicant can log back in, change their address, e-mail, etc., and their specialty.  I am trying to get the checkboxes that they chose during their initial application to be "checked" already for them when they get to this page.  My problem is, this isn't necessarily a 1 to 1 relationship. 

Here is what I have so far...

The initial form is:
-----------------------------------------------------------------------------------------------------------------------------
[code=php:0]
<input type="checkbox" f=1 name="discipline_array[]" value="Science Education" onClick="y(this)">
    Science Education<br>
&nbsp;
    <input type="checkbox" f=1 name="discipline_array[]" value="Space Physics - Aeronomy - Planetary Science" onClick="y(this)">
    Space Physics/Aeronomy/Planetary Science <br>
&nbsp;
    <input type="checkbox" f=1 name="discipline_array[]" value="Volcanology - Geochemistry - Petrology" onClick="y(this)">
    Volcanology/Geochemistry/Petrology<br>
[/code]
--------------------------------------------------------------------------------------------------------------------------------


So the code:
---------------------------------------------------------------------------------------------------------------------------------
[code=php:0]
if ($discipline_array == "Volcanology - Geochemistry - Petrology") {
?>
  <input type="checkbox" name="discipline_array" value="Volcanology - Geochemistry - Petrology" checked/> Volcanology - Geochemistry - Petrology
<?php } else { ?> 
  <input type="checkbox" name="discipline_array" value="Volcanology - Geochemistry - Petrology" /> Volcanology - Geochemistry - Petrology
<?php } ?>
[/code]
--------------------------------------------------------------------------------------------------------------------------------


works fine, IF they have only chosen Volcanology - Geochemistry - Petrology as their specialty.  If they have chosen 2 however, it will not work.  I know I can write nested elseif statement, but with around 10 specialties, that seems inefficient at best.

Can anyone help me out here?  Any assistance anyone could provide would be greatly appreciated.  Thank you so much for your time.

-chaz
Ok so I answered my own question...


For anyone who may be interested...

[code]
<?
$discipline_array=row['discipline'];  //populated from mySQL database
echo ' <input type="checkbox" name="discipline_array[]" value="Geography"';
if (strpos($discipline_array, 'Geography') !== false) {
echo ' checked="checked"';
}
echo " /> Geography\n <br>";
?>
[/code]


f'ing boom

-chaz
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.