Can one variable be fed from 2 sources?

danieli 24 Feb, 2009
I am trying to build a form with two selection boxes of e-mail addresses. The first list is managers, the second list is supervisors.

Using the "multi-page form" div technique, I am showing/hiding one dropdown, and the user can click a button to alternate/swap out the dropdown list.

Is it possible to somehow have both dropdowns feed the same "Dynamic To" variable for e-mail? If so, I am having troubles figuring it out.

Things I have tried:
[list=1]
  • Letting both lists use the same variable name... this attempt only worker for the 2nd list... as it was defined to use the variable last
  • giving each list their own variable, use a 3rd variable for the actual "Dynamic To", and somehow shove the list selection into that variable
  • [/list:o]

    The code below follows #2:

    <?php
    global $user;
    $user = &JFactory::getUser();
    ?>
    
    <h3 style="TEXT-ALIGN: center" align="center">Phone Message Form</h3>
    
    <input type="hidden" name="subject" value="">
    <input type="hidden" name="email" value="">
    <input type="hidden" name="EmployeeName" value="<?php echo $user->name?>">
    <input type="hidden" name="MessageDate" value="<?php $today = date("F j, Y, g:i a"); PRINT "$today"; ?>">
    
    <fieldset>
    <legend>Phone Message Details</legend>
    <table cellSpacing="0" cellPadding="0" border="0" id="table1">
    	<tr>
    		<td><b>Message for:</b></td>
    		<td>
    
    <!-- begin page one -->
    <div  id="mainForm_1"> 
    
    <!-- FORM FIELDS FOR PAGE ONE HERE -->
    
    		<select name="email1">
    			<option selected value="">--- Select Message Recipient ---</option>
    			<option>email@address.com</option>
    			<option>email1@address.com</option>
    			<option>email2@address.com</option>
    			<option>email3@address.com</option>
    			<option>email4@address.com</option>
    		</select>
    		<input type=button onclick=" collapseAll(); expandElem('mainForm_2');" class="mainForm" value="Show Others" />
    
    </div>
    
    <!-- begin page two -->
    <div  id="mainForm_2"> 
    
    <!-- FORM FIELDS FOR PAGE TWO HERE -->
    		<select name="email2">
    			<option selected value="">--- Select Message Recipient ---</option>
    			<option>email10@address.com</option>
    			<option>email11@address.com</option>
    			<option>email12@address.com</option>
    			<option>email13@address.com</option>
    			<option>email14@address.com</option>
    		</select>
    		<input type=button onclick=" collapseAll(); expandElem('mainForm_1');" class="mainForm" value="Show Original" />
    </div>
    
    		</td>
    	</tr>
    	<tr>
    		<td><b>Caller's Name:</b></td>
    		<td><input type="text" name="CallName" size="50" value=""></td>
    	</tr>
    	<tr>
    		<td><b>Company:</b></td>
    		<td><input type="text" name="CallCo" size="50" value=""></td>
    	</tr>
    	<tr>
    		<td><b>Location:</b></td>
    		<td><input type="text" name="CallLoc" size="50" value=""></td>
    	</tr>
    	<tr>
    		<td><b>Phone Number:</b></td>
    		<td>(<input type="text" name="CallPh1" size="5" value="">) <input type="text" name="CallPh2" size="5" value=""> - <input type="text" name="CallPh3" size="5" value=""> Ext:<input type="text" name="CallPh4" size="5" value=""></td>
    	</tr>
    	<tr>
    		<td><b>Email:</b></td>
    		<td><input type="text" name="CallEmail" size="50" value=""></td>
    	</tr>
    	<tr>
    		<td><b>Reason For Calling:</b></td>
    		<td><textarea name="CallReason" cols="50" rows="10"></textarea></td>
    	</tr>
    </table>
    </fieldset>
    <fieldset>
    <legend>Submit</legend>
    <center><input type="submit" value="Send Message"><input type="reset" value="Reset Form"></center>
    </fieldset>
    </center>


    ... and my attempt to shove the selected list item into the variable was in the following On Submit code:
    <?php if (is_null($_POST['email1'])=0) {$_POST['email'] = $_POST['email1'];} ?>
    <?php if (is_null($_POST['email2'])=0) {$_POST['email'] = $_POST['email2'];} ?>


    Am I way out to left field?
    danieli 24 Feb, 2009
    I figured it out... apparently the is_null() function was stopping me.... changed my On Submit to:
    <?php if ($_POST['email1'] != null) {$_POST['email'] = $_POST['email1'];} ?>
    <?php if ($_POST['email2'] != null) {$_POST['email'] = $_POST['email2'];} ?>

    ...and everything worked!
    This topic is locked and no more replies can be posted.