Forum Moderators: coopster

Message Too Old, No Replies

PHP newbie requesting help

         

mortickles

11:21 pm on May 2, 2004 (gmt 0)

10+ Year Member



I've been working on some minor shopping cart improvements and I keep running into little roadblocks that I just don't understand.

Problem: I wanted to add a drop down menu for the customer to select the month and year for the cc expiration date instead of having them type in the month and year in one field (mmyy).

The old code was this:

<input type=text name="x_Exp_Date" size=6 maxlength=4>

My plan is to create two drop-down selections with two separate variables like this:
<select name="month">
<option value="01" >01</option>
<option value="02" >02</option>
<option value="03" >03</option>
<option value="04" >04</option>
<option value="05" >05</option>
<option value="06" >06</option>
<option value="07" >07</option>
<option value="08" >08</option>
<option value="09" >09</option>
<option value="10" >10</option>
<option value="11" >11</option>
<option value="12" >12</option>
</select>

<select name="year">
<option value="04" >2004</option>
<option value="05" >2005</option>
<option value="06" >2006</option>
<option value="07" >2007</option>
<option value="08" >2008</option>
<option value="09" >2009</option>
<option value="10" >2010</option>
</select>

and then combine them into one field with a hidden field like this:

<input type="hidden" name="x_Exp_Date" value="<? echo $month$year?>">

My credit card processor returns an error message that the date is invalid. I've tried lots of different syntax variations for the x_Exp_Date value with no improvement. Is there an error in my logic that I'm not seeing? Is it syntax? Any help would be greatly, greatly appreciated!

isitreal

12:29 am on May 3, 2004 (gmt 0)

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



You didn't concatenate the date string:

<? echo $month$year?>

needs to be:

<? echo $month . $year?>

Depending on what format your credit card processor needs the data, that should do it.

StupidScript

9:25 pm on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your form is delivered immediately to the credit card processor without any intermediary step to collect the date values from the original form, then PHP won't be able to determine the values using the code you posted.

Are your visitors going to a confirmation page before the data is submitted to the cc company? If so, then THAT is where the concatenation of the date values will occur.

If there is no intermediary page to handle the concatenation, then you may consider a client-side solution to handle the concatenation and the assignment of the result to the hidden field's value:

i.e.:
<script type="text/javascript" language="javascript">
//Set temp variables to empty
mon="";
yer="";
function addMonth(frm,mon) { frm.x_Exp_D.value=mon+yer; }
function addYear(frm,yer) { frm.x_Exp_D.value=mon+yer; }
</script>
<select name="month" onchange="addMonth(this.form,this.options[this.selectedIndex].value)">
and
<select name="year" onchange="addYear(this.form,this.options[this.selectedIndex].value)">

In the two Javascript functions you'll note that I suggest concatenating both values each time. That way it doesn't matter which order they do them in. Also, you will want to verify that the "x_Exp_D" value is of the proper length before allowing the form to submit.

StupidScript

9:41 pm on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oops...I always forget something! Here is a working, modified version:

<script type="text/javascript" language="javascript">
//Set global variables to empty
mon="";
yer="";
function addMonth(frm,mont) {
//Assign value of select element to "mon" global
mon=mont;
frm.x_Exp_Date.value=mon+yer;
}
function addYear(frm,yeer) {
//Assign value of select element to "yer" global
yer=yeer;
frm.x_Exp_Date.value=mon+yer;
}
</script>

Everything else is okay. Sorry! :)