Using Drupal 5.2
Attempting to create what will be a multistep order form. Trying to incorporate our affiliate tracking system (another drupal module) with it. Basically, when someone comes in via an affilate link, we set two cookies, using standard php cookie setting functions. That part works fine. When someone visits our order form, we want to grab those two cookies and embed them into the form (hidden fields):
The reason I'm giving you all this detail about the cookies is, when I include the code to grab the cookies, the multistep form stops working!
---Example Code (Lifted directly from our order module source, where we're playing with this currently) ---
function abc_module_order_form($form_values = NULL)
{
global $user;
if (!isset($form_values)) {
$step = 1;
}
else {
$step = $form_values['step'] + 1;
}
$form['step'] = array(
'#type' => 'textfield',
'#value' => $step,
);
switch ($step) {
case 1:
if($_COOKIE["cookie1"]){
$c1= $_COOKIE["cookie1"];
if ($_COOKIE["cookie2"]){
$c2=$_COOKIE["cookie2"];
}
}
$form['c1'] = array(
'#type' => 'hidden',
'#default_value' => $c1,
);
$form['c2'] = array(
'#type' => 'hidden',
'#default_value' => $c2,
);
break;
case 2:
$form['c1'] = array('#type' => 'hidden','#value' => $form_values['c2']);
$form['c2'] = array('#type' => 'hidden','#value' => $form_values['c2']);
break;
}
$form['#multistep'] = TRUE;
$form['#redirect'] = FALSE;
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Continue'),
);
return $form;
}We call this using the standard drupal_get_form method (from a menu callback)... As written above, it *should* display a simple form, showing a text box with the current step number (1..2....3...etc) and a continue button. As written above, when you click continue, the step number never grows, it says "1" forever. If you comment out the four lines containing $_COOKIE calls, the form works just fine (Starts on step 1, you continue, it goes to 2, then 3, then 4, so on).
With $_COOKIE, the form processing breaks down, without $_COOKIE, it works just fine.
I guess we could re-order the form a bit and pull the cookies *after* the visitor has performed all of the steps, perhaps in the final process when we generate the order/etc, but I'm trying to understand why retrieving the cookies kills everything, so I can better plan for these things in the future. :)
Searching kept turning up problems with login/etc (drupal not being able to set it's own cookies, for instance), but nothing like this, so I guess I'm left pondering if this is something simple I'm missing, a known issue, or is by design.. :)
Comments
try this
I think you should have a #value for #type => hidden and not a #default_value.
So I think the switch statement should be as follows :
Crud.. I should have caught
Crud.. I should have caught that before I posted the code in.. that was leftover from when we were using c1 and c2 as textfield form entries, not hidden. Sadly even changing them over to #value it does the same thing... Infact, I can leave the $form declaring lines in as they are and they don't cause a problem, it's the $_COOKIE lines that cause the issue.... (If I comment out the $_COOKIE calls, the form runs)... I think for now we'll just chalk it up as one of those "interesting things" with no explanation, code around it, and go from there.