How do I move Name to top of subscribe form?

I have searched for 3 days on how to move my “first name” attribute to the top of the subscribe form. It sits under the confirm email and it looks really bad! If anyone can help, I would so appreciate it!
Thank you!!!

I edited the subscribelib2.php function ListAttributes(…) function to display my name attribute above the emails and then display other contact information below those emails. You can check the page out by going to https://www.sudburyminutemen.org/lists/?p=subscribe&id=1. You can check out my code for ListAttributes function. I have commented the section for my Name attribute above the emails and the section for all other attributes below the emails. You might need to substitute your specific attribute names.

Thank you so much mslamkin. Your subscribe form is great! I’ll check it out when I get on my computer.

I realize that you won’t see the revised subscribelib2.php when you view the source of my subscribe page. Not sure how to share the code with you or others. I know there was one other person who asked a similar question a while ago. Is there a way to share the code with others besides copying the entire file in this forum?

Here is the modified ListAttributes function in subscribelib2.php that I use so that my subscribe page has the subscriber’s Name above the email address and confirmation email address. The other subscriber attributes are listed below the cofirmation email address. The choice of html vs text format is placed below these other attributes. What’s important is to determine the $attr[‘name’].

function ListAttributes($attributes, $attributedata, $htmlchoice = 0, $userid = 0, $emaildoubleentry = ‘no’)
{
global $strPreferHTMLEmail, $strPreferTextEmail,
$strEmail, $tables, $table_prefix, $strPreferredFormat, $strText, $strHTML;
/* if (!sizeof($attributes)) {
return “No attributes have been defined for this page”;
}
*/
if ($userid) {
$data = array();
$current = Sql_Fetch_array_Query(“select * from {$GLOBALS[‘tables’][‘user’]} where id = $userid”);
$datareq = Sql_Query(“select * from {$GLOBALS[‘tables’][‘user_attribute’]} where userid = $userid”);
while ($row = Sql_Fetch_Array($datareq)) {
$data[$row[‘attributeid’]] = $row[‘value’];
}

    $email = obfuscateEmailAddress($current['email']);
    $htmlemail = $current['htmlemail'];
    // override with posted info
    foreach ($current as $key => $val) {
        if (isset($_POST[$key]) && $key != 'password') {
            $current[$key] = $val;
        }
    }
} else {
    if (isset($_REQUEST['email'])) {
        $email = stripslashes($_REQUEST['email']);
    } else {
        $email = '';
    }
    if (isset($_POST['htmlemail'])) {
        $htmlemail = $_POST['htmlemail'];
	} elseif (!isset($_POST["subscribe"]) && isset($_GET['htmlemail']) && in_array($_GET['htmlemail'], [1,0])) {
  		$htmlemail = $_GET["htmlemail"];
    }
    $data = array();
    $current = array();
}

$textlinewidth = sprintf('%d', getConfig('textline_width'));
if (!$textlinewidth) {
    $textlinewidth = 40;
}
list($textarearows, $textareacols) = explode(',', getConfig('textarea_dimensions'));
if (!$textarearows) {
    $textarearows = 10;
}
if (!$textareacols) {
    $textareacols = 40;
}

$html = '';
if (!isset($_GET['page']) || (isset($_GET['page']) && $_GET['page'] != 'import1')) {

// start for Name
// Write attribute field for Name
$attids = implode(’,’, array_keys($attributes));
$output = array();
if ($attids) {
$res = Sql_Query(“select * from {$GLOBALS[‘tables’][‘attribute’]} where id in ($attids)”);
while ($attr = Sql_Fetch_Array($res)) {
$output[$attr[‘id’]] = ‘’;
if (!isset($data[$attr[‘id’]])) {
$data[$attr[‘id’]] = ‘’;
}
$attr[‘required’] = $attributedata[$attr[‘id’]][‘required’];
$attr[‘default_value’] = $attributedata[$attr[‘id’]][‘default_value’];
$fieldname = ‘attribute’.$attr[‘id’];
if ($userid && !isset($_POST[$fieldname])) {
// post values take precedence
$val = Sql_Fetch_Row_Query(sprintf(‘select value from %s where
attributeid = %d and userid = %d’, $GLOBALS[‘tables’][‘user_attribute’], $attr[‘id’], $userid));
$_POST[$fieldname] = $val[0];
} elseif (!isset($_POST[$fieldname])) {
$_POST[$fieldname] = 0;
}
if ($attr[‘name’] == ‘Name’) {
// Name is textline so switch is not needed and textline output is defined as normal
$output[$attr[‘id’]] .= sprintf("\n".’

%s
’,
$attr[‘required’] ? ‘required’ : ‘attributename’, $attr[‘required’] ? $attr[‘name’].’ *’ : $attr[‘name’]);
$output[$attr[‘id’]] .= sprintf(’
‘, $fieldname,
$textlinewidth,
$_POST[$fieldname] ? str_replace(’"’, ‘"’, stripslashes($_POST[$fieldname])) : ($data[$attr[‘id’]] ? $data[$attr[‘id’]] : $attr[‘default_value’]));
if ($attr[‘required’]) {
$output[$attr[‘id’]] .= sprintf(‘’,
$fieldname, $attr[‘name’]);
}
$output[$attr[‘id’]] .= “ \n”;}
}
}
// make sure the order is correct
foreach ($attributes as $attribute => $listorder) {
    if (isset($output[$attribute])) {
        $html .= $output[$attribute];
    }
}

// ***************** end for Name
// ***************** for email and confirmation email, as in original subscribelib2.php file
// ***************** IMPORTANT, be sure to modify next line so we are concatenating the html string
$html .= sprintf(’

%s *
', $GLOBALS['strEmail'], htmlspecialchars($email), $textlinewidth, $GLOBALS['strEmail']); }

// BPM 12 May 2004 - Begin
if ($emaildoubleentry == ‘yes’) {
if (!isset($_REQUEST[‘emailconfirm’])) {
$_REQUEST[‘emailconfirm’] = ‘’;
}
$html .= sprintf(’

%s *
', $GLOBALS['strConfirmEmail'], htmlspecialchars(stripslashes($_REQUEST['emailconfirm'])), $textlinewidth, $GLOBALS['strConfirmEmail']); } // BPM 12 May 2004 - Finish
if ((isset($_GET['page']) && $_GET['page'] != 'import1') || !isset($_GET['page'])) {
    if (ASKFORPASSWORD) {
        // we only require a password if there isnt one, so they can set it
        // otherwise they can keep the existing, if they do not enter anything
        if (!isset($current['password']) || !$current['password']) {
            $pwdclass = 'required';
            $js = sprintf('<script language="Javascript" type="text/javascript">addFieldToCheck("password","%s");</script>',
                $GLOBALS['strPassword']);
            $js2 = sprintf('<script language="Javascript" type="text/javascript">addFieldToCheck("password_check","%s");</script>',
                $GLOBALS['strPassword2']);
            $html .= '<input type="hidden" name="passwordreq" value="1" />';
        } else {
            $pwdclass = 'attributename';
            $html .= '<input type="hidden" name="passwordreq" value="0" />';
        }

        $html .= sprintf('
%s
%s ', $pwdclass, $GLOBALS['strPassword'], $textlinewidth, $js); $html .= sprintf('
%s
%s ', $pwdclass, $GLOBALS['strPassword2'], $textlinewidth, $js2); } }

// ************************** for all attributes except Name
$attids = implode(’,’, array_keys($attributes));
$output = array();
if ($attids) {
$res = Sql_Query(“select * from {$GLOBALS[‘tables’][‘attribute’]} where id in ($attids)”);
while ($attr = Sql_Fetch_Array($res)) {
$output[$attr[‘id’]] = ‘’;
if (!isset($data[$attr[‘id’]])) {
$data[$attr[‘id’]] = ‘’;
}
$attr[‘required’] = $attributedata[$attr[‘id’]][‘required’];
$attr[‘default_value’] = $attributedata[$attr[‘id’]][‘default_value’];
$fieldname = ‘attribute’.$attr[‘id’];
// print “

”.$attr[“id”]."";
if ($userid && !isset($_POST[$fieldname])) {
// post values take precedence
$val = Sql_Fetch_Row_Query(sprintf(‘select value from %s where
attributeid = %d and userid = %d’, $GLOBALS[‘tables’][‘user_attribute’], $attr[‘id’], $userid));
$_POST[$fieldname] = $val[0];
} elseif (!isset($_POST[$fieldname])) {
$_POST[$fieldname] = 0;
}
// start for remaining attributes, beginning of condition
if ($attr[‘name’] != ‘Name’) {
switch ($attr[‘type’]) {
case ‘checkbox’:
$output[$attr[‘id’]] = ‘’;
// what they post takes precedence over the database information
if ($_POST[$fieldname]) {
$checked = $POST[$fieldname] ? ‘checked=“checked”’ : ‘’;
} else {
$checked = $data[$attr[‘id’]] ? ‘checked=“checked”’ : ‘’;
}
$output[$attr[‘id’]] .= sprintf("\n".’<input type=“checkbox” name="%s" value=“on” %s class=“attributeinput” id="’.$fieldname.’" />’,
$fieldname, $checked);
$output[$attr[‘id’]] .= sprintf("\n".’%s’,
$attr[‘required’] ? ‘required’ : ‘attributename’, $attr[‘required’] ? stripslashes($attr[‘name’]).’ *’ : stripslashes($attr[‘name’]));
if ($attr[‘required’]) {
$output[$attr[‘id’]] .= sprintf(‘’,
$fieldname, $attr[‘name’]);
}
break;
case ‘radio’:
$output[$attr[‘id’]] .= sprintf("\n".’
%s
’,
$attr[‘required’] ? ‘required’ : ‘attributename’, $attr[‘required’] ? stripslashes($attr[‘name’]).’ *’ : stripslashes($attr[‘name’]));
$values_request = Sql_Query(“select * from $table_prefix”.'listattr’.$attr[‘tablename’].’ order by listorder,name’);
while ($value = Sql_Fetch_array($values_request)) {
if (!empty($_POST[$fieldname])) {
$checked = $POST[$fieldname] == $value[‘id’] ? ‘checked=“checked”’ : ‘’;
} elseif ($data[$attr[‘id’]]) {
$checked = $data[$attr[‘id’]] == $value[‘id’] ? ‘checked=“checked”’ : ‘’;
} else {
$checked = $attr[‘default_value’] == $value[‘name’] ? ‘checked=“checked”’ : ‘’;
}
$output[$attr[‘id’]] .= sprintf(’<input type=“radio” class=“attributeinput” name="%s" id="’.$fieldname.$value[‘id’].’" value="%s" %s /> %s ‘,
$fieldname, $value[‘id’], $checked, ‘’.$value[‘name’].’’);
}
if ($attr[‘required’]) {
$output[$attr[‘id’]] .= sprintf(‘’,
$fieldname, $attr[‘name’]);
}
break;
case ‘select’:
$output[$attr[‘id’]] .= sprintf("\n".’
%s
’,
$attr[‘required’] ? ‘required’ : ‘attributename’, $attr[‘required’] ? stripslashes($attr[‘name’]).’ *’ : stripslashes($attr[‘name’]));
$values_request = Sql_Query(“select * from $table_prefix”.'listattr’.$attr[‘tablename’].’ order by listorder,name’);
$output[$attr[‘id’]] .= sprintf(’ ’,
$data[$attr[‘id’]], $fieldname);
while ($value = Sql_Fetch_array($values_request)) {
if (!empty($_POST[$fieldname])) {
$selected = $_POST[$fieldname] == $value[‘id’] ? ‘selected=“selected”’ : ‘’;
} elseif ($data[$attr[‘id’]]) {
$selected = $data[$attr[‘id’]] == $value[‘id’] ? ‘selected=“selected”’ : ‘’;
} elseif (!empty($attr[‘default_value’])) {
$selected = strtolower($attr[‘default_value’]) == strtolower($value[‘name’]) ? ‘selected=“selected”’ : ‘’;
} elseif (strtolower($attr[‘name’]) == ‘country’ && !empty($_SERVER[‘GEOIP_COUNTRY_NAME’])) {
$selected = strtolower($SERVER[‘GEOIP_COUNTRY_NAME’]) == strtolower($value[‘name’]) ? ‘selected=“selected”’ : ‘’;
} else {
$selected = ‘’;
}
if (preg_match(’/^’.preg_quote(EMPTY_VALUE_PREFIX).’/i’, $value[‘name’])) {
$value[‘id’] = ‘’;
}
$output[$attr[‘id’]] .= sprintf(’<option value="%s" %s>%s’, $value[‘id’], $selected,
stripslashes($value[‘name’]));
}
$output[$attr[‘id’]] .= ‘’;
break;
case ‘checkboxgroup’:
$output[$attr[‘id’]] .= sprintf("\n".’
%s
’,
$attr[‘required’] ? ‘required’ : ‘attributename’, $attr[‘required’] ? stripslashes($attr[‘name’]).’ *’ : stripslashes($attr[‘name’]));
$values_request = Sql_Query(“select * from $table_prefix”.'listattr’.$attr[‘tablename’].’ order by listorder,name’);
$output[$attr[‘id’]] .= sprintf(’’);
$first_td = 0;
while ($value = Sql_Fetch_array($values_request)) {
$selected = ‘’;
if (is_array($_POST[$fieldname])) {
$selected = in_array($value[‘id’], $_POST[$fieldname]) ? ‘checked’ : ‘’;
} elseif ($data[$attr[‘id’]]) {
$selection = explode(’,’, $data[$attr[‘id’]]);
$selected = in_array($value[‘id’], $selection) ? ‘checked=“checked”’ : ‘’;
}
if ($first_td == 0) {
$output[$attr[‘id’]] .= sprintf(’<input type=“checkbox” name="%s[]" class=“attributeinput” value="%s" %s id="’.$fieldname.$value[‘id’].’" /> %s’,
$fieldname, $value[‘id’], $selected, stripslashes($value[‘name’]));
$output[$attr[‘id’]] .= sprintf(’’);
} else {
$output[$attr[‘id’]] .= sprintf(’
<input type=“checkbox” name="%s[]" class=“attributeinput” value="%s" %s id="’.$fieldname.$value[‘id’].’" /> %s ’,
$fieldname, $value[‘id’], $selected, stripslashes($value[‘name’]));
}
++$first_td;
}
$first_td = 0;
break;
case ‘textline’:
$output[$attr[‘id’]] .= sprintf("\n".’
%s
’,
$attr[‘required’] ? ‘required’ : ‘attributename’, $attr[‘required’] ? $attr[‘name’].’ *’ : $attr[‘name’]);
$output[$attr[‘id’]] .= sprintf(’
‘, $fieldname,
$textlinewidth,
$_POST[$fieldname] ? str_replace(’"’, ‘"’, stripslashes($_POST[$fieldname])) : ($data[$attr[‘id’]] ? $data[$attr[‘id’]] : $attr[‘default_value’]));
if ($attr[‘required’]) {
$output[$attr[‘id’]] .= sprintf(‘’,
$fieldname, $attr[‘name’]);
}
break;
case ‘textarea’:
$output[$attr[‘id’]] .= sprintf("\n".’
%s
’, $attr[‘required’] ? ‘required’ : ‘attributename’,
$attr[‘required’] ? $attr[‘name’].’ *’ : $attr[‘name’]);
$output[$attr[‘id’]] .= sprintf(’
%s’,
$fieldname, $textarearows, $textareacols,
$_POST[$fieldname] ? str_replace(array(’>’, ‘<’), array(’>’, ‘<’),stripslashes($_POST[$fieldname])) : ($data[$attr[‘id’]] ? str_replace(array(’>’, ‘<’), array(’>’, ‘<’),stripslashes($data[$attr[‘id’]])) : $attr[‘default_value’]));
if ($attr[‘required’]) {
$output[$attr[‘id’]] .= sprintf(‘’,
$fieldname, $attr[‘name’]);
}
break;
case ‘hidden’:
$output[$attr[‘id’]] .= sprintf(’’,
$fieldname, $data[$attr[‘id’]] ? $data[$attr[‘id’]] : $attr[‘default_value’]);
break;
case ‘date’:
require_once dirname(FILE).’/date.php’;
$date = new Date();
$postval = $date->getDate($fieldname);
if ($data[$attr[‘id’]]) {
$val = $data[$attr[‘id’]];
} else {
$val = $postval;
}
                $output[$attr['id']] = sprintf("\n".'<tr><td><div class="%s">%s</div>',
                    $attr['required'] ? 'required' : 'attributename', $attr['required'] ? $attr['name'].' *' : $attr['name']);
                $output[$attr['id']] .= sprintf('</td><td class="attributeinput">
        %s</td></tr>', $date->showInput($fieldname, '', $val));
                break;
            default:
                print '<!-- error: huh, invalid attribute type -->';
        }
        $output[$attr['id']] .= "</td></tr>\n";
    }

// ***************** end for remaining attributes, closing of condition
}
}

// make sure the order is correct
foreach ($attributes as $attribute => $listorder) {
    if (isset($output[$attribute])) {
        $html .= $output[$attribute];
    }
}

// for html choice
switch ($htmlchoice) {
case ‘textonly’:
if (!isset($htmlemail)) {
$htmlemail = 0;
}
$html .= sprintf(’’);
break;
case ‘htmlonly’:
if (!isset($htmlemail)) {
$htmlemail = 1;
}
$html .= sprintf(’’);
break;
case ‘checkfortext’:
if (!isset($htmlemail)) {
$htmlemail = 1;
}
$html .= sprintf(’



<input type=“checkbox” name=“textemail” value=“1” %s id=“textemail” />

%s
‘, !$htmlemail ? ‘checked=“checked”’ : ‘’, $strPreferTextEmail);
break;
case ‘radiotext’:
if (!isset($htmlemail)) {
$htmlemail = 0;
}
$html .= sprintf(’
%s

<input type=radio name=“htmlemail” value=“0” %s id=“htmlemail0” />
%s
<input type=radio name=“htmlemail” value=“1” %s id=“htmlemail1” />
%s
’,
$strPreferredFormat,
!$htmlemail ? ‘checked=“checked”’ : ‘’, $strText,
$htmlemail ? ‘checked=“checked”’ : ‘’, $strHTML);
break;
case ‘radiohtml’:
if (!isset($htmlemail)) {
$htmlemail = 1;
}
$html .= sprintf(’
%s
<input type=“radio” name=“htmlemail” value=“0” %s id=“htmlemail0” />
%s    
<input type=“radio” name=“htmlemail” value=“1” %s id=“htmlemail1” />
%s ’,
$strPreferredFormat,
!$htmlemail ? ‘checked=“checked”’ : ‘’, $strText,
$htmlemail ? ‘checked=“checked”’ : ‘’, $strHTML);
break;
case ‘checkforhtml’:
default:
if (!isset($htmlemail)) {
$htmlemail = 1;
}
$html .= sprintf(’
<input type=“checkbox” name=“htmlemail” value=“1” %s id=“htmlemail” />
%s ’, $htmlemail ? ‘checked=“checked”’ : ‘’, $strPreferHTMLEmail);
break;
}
$html .= “\n”;
return $html;

}

1 Like