Jump to content

setting a form selection to a php session


Recommended Posts

I need help setting a form selection to a php session.

 

I'm generating one of my form dropdown menus dynamically, based on the selection of two other drop down menus. But I need the value selected of the generated drop down menu stored so the value be recalled when one of the two other menus change.

 

See this page:

http://beta.area51entertainment.co/signup

 

Change the birthday setting to what ever you want. You'll see that if you set the Month, Then the Day, then the year, the day resets back to "Day" because the year menus onchange call triggers the menu to regenerate. I some how need the day selected to be stored in a session and reselected once the year or month menu changes (unless the day option selected does fit within the new menu generated. I.E; someone selects the 31, but then selects a month with only 30 days.).

 

It maybe that I'm not doing anything with the ajax response, but since I'm triggering a PHP Session variable do I need to? I can't send the response back to the menu id tag, since that'll wipe out the menu generation AJAX since it uses the same id.

 

Maybe send it back to a hidden div?

 

Here's the current code:

 

Form:

elseif(isset($_GET['signup'])){
session_start();
$_SESSION['register_user']="add";
$year_menu=generateBirthYearMenu(date("Y"));
$day_menu=generateBirthDayMenu(null,null);
$switch="notloggedin";
$content.='<div class="register_ad_wrapper">
<div class="register_wrapper">
	<form name="sign_up_type" action="./signup.php" method="post">
	<input type="hidden" name="newuser" id="newuser" value="add" />
		<div class="register_account_type_position">
		<p class="signup_title">Sign-Up for - Step One</p>
		<p class="register_account_type_title">Account Type:</p>
		<span class="register_account_type_personal_position"><input type="radio" value="personal" name="register_account_type" id="register_account_type_personal" class="register_account_type_personal" onclick="sendReq(\'personal\');" '; if((isset($_SESSION['account_type']) && $_SESSION['account_type']=="personal") || !isset($_SESSION['account_type'])){ $content.='checked="checked" '; } $content.='/> <label for="register_account_type_personal"><span class="register_radio_text">Personal</span></label></span>
		<span class="register_account_type_music_position"><input type="radio" value="music" name="register_account_type" id="register_account_type_music" class="register_account_type_music" onclick="sendReq(\'music\');" '; if(isset($_SESSION['account_type']) && $_SESSION['account_type']=="music"){ $content.='checked="checked" '; } $content.='/> <label for="register_account_type_music"><span class="register_radio_text">Band/Recording Artist</span></label></span>
		<span class="register_account_type_film_position"><input type="radio" value="film" name="register_account_type" id="register_account_type_film" class="register_account_type_film" onclick="sendReq(\'film\');" '; if(isset($_SESSION['account_type']) && $_SESSION['account_type']=="film"){ $content.='checked="checked" '; } $content.='/> <label for="register_account_type_film"><span class="register_radio_text">Filmmaker/Actor</span></label></span>
		<span class="register_account_type_business_position"><input type="radio" value="business" name="register_account_type" id="register_account_type_business" class="register_account_type_business" onclick="sendReq(\'business\');" '; if(isset($_SESSION['account_type']) && $_SESSION['account_type']=="business"){ $content.='checked="checked" '; } $content.='/> <label for="register_account_type_business"><span class="register_radio_text">Business</span></label></span>
		<span class="register_account_type_other_position"><input type="radio" value="business" name="register_account_type" id="register_account_type_other" class="register_account_type_other" onclick="sendReq(\'other\');" '; if(isset($_SESSION['account_type']) && $_SESSION['account_type']=="other"){ $content.='checked="checked" '; } $content.='/> <label for="register_account_type_other"><span class="register_radio_text">Other</span></label></span>
		</div>
	<div id="signup_forms">
		<div class="register_form_wrapper">
		<p class="register_form_position">
		<label for="register_email"><span class="register_form_text">Email:</span></label> <input type="email" value="'.$_SESSION['register_email'].'" name="register_email" id="register_email" class="register_form" />
		</p>
		<p class="register_form_position">
		<label for="register_fname"><span class="register_form_text">First Name:</span></label> <input type="text" value="'.$_SESSION['register_fname'].'" name="register_fname" id="register_fname" class="register_form" />
		</p>
		<p class="register_form_position">
		<label for="register_lname"><span class="register_form_text">Last Name:</span></label> <input type="text" value="'.$_SESSION['register_lname'].'" name="register_lname" id="register_lname" class="register_form" />
		</p>
		<p class="register_form_position">
		<label for="register_check_email"><span class="register_form_text">Re-enter Email:</span></label> <input type="email" value="'.$_SESSION['register_check_email'].'" name="register_check_email" id="register_check_email" class="register_form" />
		</p>
		<p class="register_form_position">
		<label for="register_password"><span class="register_form_text">New Password:</span></label> <input type="password" value="'.$_SESSION['register_password'].'" name="register_password" id="register_password" class="register_form" />
		</p>
		<p class="register_form_position">
		<label for="register_check_password"><span class="register_form_text">Re-enter Password:</span></label> <input type="password" value="'.$_SESSION['register_check_password'].'" name="register_check_password" id="register_check_password" class="register_form" />
		</p>
		<p class="register_form_position_gender">
		<label for="register_gender">Gender:</label>
		<select name="register_gender" id="register_gender">
		<option value=""></option>
		<option value="Female">Female</option>
		<option value="Male">Male</option>
		</select>
		</p>
		<p class="register_form_position_birthday">
		Birthday:
		<select name="register_month" id="register_month" onchange="sndReq(register_year.value,this.value);">
		<option value="">Month</option>
		<option value="January">January</option>
		<option value="February">February</option>
		<option value="March">March</option>
		<option value="April">April</option>
		<option value="June">June</option>
		<option value="July">July</option>
		<option value="August">August</option>
		<option value="September">September</option>
		<option value="October">October</option>
		<option value="November">November</option>
		<option value="December">December</option>
		</select>
		<select name="register_day" id="register_day" onchange="sendRequest(this.value);">
		<option>Day</option>'."\n".
		$day_menu
		.'</select>
		<select name="register_year" id="register_year" onchange="sndReq(this.value,register_month.value);">
		<option>Year</option>'."\n".
		$year_menu
		.'</select>
		</p>
		</div>
	</div>
			<div class="register_membership_type_position">
			<span class="register_membership_type_title">Membership Type:</span>
			<span class="register_membership_type_basic_position"><input type="radio" value="basic" name="register_membership_type" id="register_membership_type_basic" class="register_membership_type_basic" onchange="changeButton(\'basic\');" '; if((isset($_SESSION['membership_type']) && $_SESSION['membership_type']=="basic") || !isset($_SESSION['membership_type'])){ $content.='checked="checked" '; } $content.='/> <label for="register_membership_type_basic"><span class="register_radio_text">Basic</span></label></span>
			<span class="register_membership_type_premium_position"><input type="radio" value="premium" name="register_membership_type" id="register_membership_type_premium" class="register_membership_type_premium" onchange="changeButton(\'premium\');" '; if(isset($_SESSION['membership_type']) && $_SESSION['membership_type']=="premium"){ $content.='checked="checked" '; } $content.='/> <label for="register_membership_type_premium"><span class="register_radio_text">Premium</span></label></span>
			<span class="register_membership_type_platinum_position"><input type="radio" value="platinum" name="register_membership_type" id="register_membership_type_platinum" class="register_membership_type_platinum" onchange="changeButton(\'platinum\');" '; if(isset($_SESSION['membership_type']) && $_SESSION['membership_type']=="platinum"){ $content.='checked="checked" '; } $content.='/> <label for="register_membership_type_platinum"><span class="register_radio_text">Platinum</span></label></span>
			<span class="learn_more_position">(<a href="/signup?memberships">Learn More About Membership Types</a>)</span>
			</div>
		<div class="form_question_wrapper">
		<p class="register_form_question_title">Random Question (&#66;&#111;&#116; Screener):</p>
		<p class="register_form_question_position">
		<label for="register_bot"><span class="register_form_question_text">What is the primary color of this page (starts with "&#71;"):</span></label> 
		<input type="text" value="'.$_SESSION['register_bot'].'" name="register_bot" id="register_bot" class="register_question_form" />
		</p>
		</div>
		<p class="signup_agreement">
		By clicking the sign-up button below you are agreeing to our Terms of Services and our Privacy Policy.
		</p>
		<p class="register_form_position register_submission">
		<input type="submit" value="Sign Up" class="register_button_position" id="register_submit_button" name="register_submit_button" />
		</p>
	</form>
</div>
<div class="ad_wrapper">
Ad
</div>
</div>
';
}

 

AJAX call:

function requestObj() {
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}


var http3 = requestObj();

function sendRequest(day_selected){
    http3.open('get', 'signup_sessionset.php?day_selected='+day_selected, true);
    http3.onreadystatechange = handleResquest;
    http3.send(null);
}

 

Function that generates the menu:

function generateBirthDayMenu($month,$year){
session_start();
$_SESSION['month']=$month;
$_SESSION['year']=$year;
$day_array=array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28);
$month_array1=array("April", "June", "September", "November");
$month_array2=array("January", "March", "May", "July", "August", "October", "December");

if($month=="February" && ($year % 4) ==0 && (($year % 100) !=0 || ($year % 400) ==0)){
array_push($day_array, "29");
}
elseif(!isset($month)){
array_push($day_array, "29", "30", "31");
}
else{

}

foreach($month_array1 as $month_value){
if($month==$month_value){
array_push($day_array, "29", "30");
}
}

foreach($month_array2 as $month_value){
if($month==$month_value){
array_push($day_array, "29", "30", "31");
}
}

foreach($day_array as $day_item){
$day.='<option value="'.$day_item.'"'; if(isset($_SESSION['birthday_day']) && $_SESSION['birthday_day']==$day_item){ $day.=' selected="selected"'; } $day.='>'.$day_item.'</option>'."\n";
}

return $day;
}

 

 

php page where the session should be set, but is not being set:

<?php
session_start();
if(isset($_GET['day_selected'])){
$_SESSION['birthday_day']=$_GET['day_selected'];
}

echo $_SESSION['birthday_day'];
?>

Link to comment
Share on other sites

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.