Input Date From Membership Signup Form

25 posts by 4 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: April 8, 2011   (RSS)

Re: [gkornbluth] Input Date From Membership Signup Form

By Jason - January 19, 2011

Hi Jerry,

Okay, I see the problem. What you need to do is to populate the $_REQUEST variables with the variables from the database. The date is being stored in the database as a single value, but we're manipulating it in the form in 3 fields. The code below is to break it apart.

Note: Make sure you put this after your code that updates the database. We don't want to overwrite submitted data.

//pre-populate date fields from the databas
//get most current $CURRENT_USER
$CURRENT_USER = _websiteLogin_getCurrentUser();

$_REQUEST['month_1']=date("n",strtotime($CURRENT_USER['student_1_dob']));
$_REQUEST['day_1']=date("j",strtotime($CURRENT_USER['student_1_dob']));
$_REQUEST['year_1']=date("Y",strtotime($CURRENT_USER['student_1_dob']));


This can be repeated for the other 3 dates.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Hi Jason,

Still lost...

I’m sure I’m missing something silly.

Neither of the following seem to work (pull the current value from the database).

(Everything else from the previous attached files is untouched)

Jerry

<tr>
<td>Date of Birth</td>
<td><?php
$lowestYear = 1920;
$highestYear = 2006;

//pre-populate date fields from the databas
//get most current $CURRENT_USER
$CURRENT_USER = _websiteLogin_getCurrentUser();

$_REQUEST['month_1']=date("n",strtotime($CURRENT_USER['student_1_dob']));
$_REQUEST['day_1']=date("j",strtotime($CURRENT_USER['student_1_dob']));
$_REQUEST['year_1']=date("Y",strtotime($CURRENT_USER['student_1_dob']));
?>
Month:
<select name="month_1">
<?php foreach(range(1,12) as $month_1): ?>
<option value="<?php echo htmlspecialchars(@$_REQUEST[$month_1]);?>"><?php echo date("F",strtotime("0000-$month_1"));?></option>
<?php endforeach ?>
</select> Day:
<select name="day_1">
<?php foreach(range(1,31)as $day_1): ?>
<option value="<?php echo htmlspecialchars(@$_REQUEST[$day_1]);?>"><?php echo $day_1;?></option>
<?php endforeach ?>
</select> Year:
<select name="year_1">
<?php foreach (range($lowestYear,$highestYear) as $year_1):?>
<option value="<?php echo htmlspecialchars(@$_REQUEST[$year_1]);?>"><?php echo $year_1;?></option>
<?php endforeach?>
</select>

</tr>


or

<tr>
<td>Date of Birth</td>
<td><?php
$lowestYear = 1920;
$highestYear = 2006;

//pre-populate date fields from the databas
//get most current $CURRENT_USER
$CURRENT_USER = _websiteLogin_getCurrentUser();

$_REQUEST['month_1']=date("n",strtotime($CURRENT_USER['student_1_dob']));
$_REQUEST['day_1']=date("j",strtotime($CURRENT_USER['student_1_dob']));
$_REQUEST['year_1']=date("Y",strtotime($CURRENT_USER['student_1_dob']));
?>
Month:
<select name="month_1">
<?php foreach(range(1,12) as $month_1): ?>
<option value="<?php echo htmlspecialchars(@$_REQUEST['$month_1']);?>"><?php echo date("F",strtotime("0000-$month_1"));?></option>
<?php endforeach ?>
</select> Day:
<select name="day_1">
<?php foreach(range(1,31)as $day_1): ?>
<option value="<?php echo htmlspecialchars(@$_REQUEST['$day_1']);?>"><?php echo $day_1;?></option>
<?php endforeach ?>
</select> Year:
<select name="year_1">
<?php foreach (range($lowestYear,$highestYear) as $year_1):?>
<option value="<?php echo htmlspecialchars(@$_REQUEST['$year_1']);?>"><?php echo $year_1;?></option>
<?php endforeach?>
</select>

</tr>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Input Date From Membership Signup Form

By Rusty - January 20, 2011 - edited: January 20, 2011

I don't know if it matters. but I put this bit of code at the very top of the page, it's like the third of fourth thins to load. (After viewer functions, calling up the records, and then the website membership check.

//pre-populate date fields from the databas
//get most current $CURRENT_USER
$CURRENT_USER = _websiteLogin_getCurrentUser();


And I know it doesn't help you at all since you're trying (as I can understand) pre-populate the edit profile portion of the birthday.

I didn't bother with it, and just have the user re-submit their birthday. I have 2 sections. a "View Profile" and an "Edit Profile"

FWIW, here's my date submit code:

<td>Birthday</td>

<td><?php
$lowestYear = 1920;
$highestYear = 2006;
?>
Month:
<select name="month">
<?php foreach(range(1,12) as $month): ?>
<option value="<?php echo $month;?>"><?php echo date("F",strtotime("0000-$month"));?></option>
<?php endforeach ?>
</select>
Day:
<select name="day">
<?php foreach(range(1,31)as $day): ?>
<option value="<?php echo $day;?>"><?php echo $day;?></option>
<?php endforeach ?>
</select>
Year:
<select name="year">
<?php foreach (range($highestYear,$lowestYear) as $year):?>
<option value="<?php echo $year;?>"><?php echo $year;?></option>
<?php endforeach?>
</select>

</tr>

Rusty

Re: [Rusty] Input Date From Membership Signup Form

By Rusty - January 20, 2011

Did some digging. I could be wrong but....

I think you might need to do an if / else statement where you compare the value of the Current Month, to the value of the Month that the "foreach" is generating, and IF == then echo a selected="selected", or maybe a selected="Current Month".

But there's the possibility that it would prevent you from changing the "Current Month" to a New Month, because Current Month was written (by the above formula) to be selected by default (as a pre-populated form)...

Just a thought.

HTH
Rusty

Re: [gkornbluth] Input Date From Membership Signup Form

Hi Rusty,

Thanks for your input.

Hopefully, Jason will be able to sort this out and help us all.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Input Date From Membership Signup Form

By Jason - January 20, 2011

Hi Jerry,

There are a couple of things happening in your code.

First is where you're outputting your values for your option tags:

<option value="<?php echo htmlspecialchars(@$_REQUEST['$month_1']);?>">


In this code you're trying to output a request variable with an index of $month_1 instead of month_1. This will actually produce an error (the @ is suppressing it). Also, outputting the $_REQUEST variable for the value will mean that you'll be giving every option in the list the same value. What we want to use is $month_1. This is the incrementing values (between 1 and 12) that our foreach loop is producing.

To set a given value as selected, we'll use the selectedIf() function. This function checks the current value being used in the foreach loop against the value we want to default to that's in our request variable.

With these changes, our code looks like this:



<select name="month_1">
<?php foreach(range(1,12) as $month_1): ?>
<option value="<?php echo 'month_1';?>" <?php selectedIf($month_1,@$_REQUEST['month_1']);?>><?php echo date("F",strtotime("0000-$month_1"));?></option>
<?php endforeach ?>
</select> Day:
<select name="day_1">
<?php foreach(range(1,31)as $day_1): ?>
<option value="<?php echo $day_1;?>" <?php selectedIf($month_1,@$_REQUEST['day_1']);?>><?php echo $day_1;?></option>
<?php endforeach ?>
</select> Year:
<select name="year_1">
<?php foreach (range($lowestYear,$highestYear) as $year_1):?>
<option value="<?php echo $year_1;?>" <?php selectedIf($month_1,@$_REQUEST['year_1']);?>><?php echo $year_1;?></option>
<?php endforeach?>
</select>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gkornbluth - January 20, 2011 - edited: January 20, 2011

Hi Jason,

Thanks for revisiting this.

The last fix got us almost there and we're gaining on it...

(After changing the $month_1 to $day_1 and $year_1 in the appropriate places)

The existing value is now pulled from the database and populates the fields in the update form.

However, when I change the date and submit the form to update the database, the new value in the database reverts to Dec 31, 1969

I just know you'll know how to fix this...

Thanks,

Jerry

I’ve attached the latest version of the profile update form.
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

member_profile17.php 42K

Re: [gkornbluth] Input Date From Membership Signup Form

By Jason - January 20, 2011

Hi Jerry,

oops. This one is the result of a typo on my part. In this line:

<option value="<?php echo 'month_1';?>"

we're actually outputting the string month_1, which is why the mktime function isn't working properly.
Try changing it to this:

<option value="<?php echo $month_1;?>"

That should take care of it.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
YES!!!

Thanks again.

I'll clean up my code and post it here.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php