Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to make the option 'Newsletter' checked by default?


Allysin

Recommended Posts

Hello :huh:

 

I am new here and I was trying to find out how to make the option 'Newsletter' checked by default? As in - it would be checked on the order form and if the customer does not want it - they would have to uncheck it.

 

I know how to make this happen in HTML but this is different (I think). I want to check it for all the order forms.

 

Thanks everyone for your help! :thumbsup:

 

Allysin

 

PS: I've tried changing the following (in create_account.php):

 

<td class="main"><?php echo tep_draw_checkbox_field('newsletter', '1') . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_NEWSLETTER_TEXT . '</span>': ''); ?></td>

 

 

to:

 

 

<td class="main"><?php echo tep_draw_checkbox_field('newsletter', '1', true) . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_NEWSLETTER_TEXT . '</span>': ''); ?></td>

 

 

and also to:

 

 

<td class="main"><?php echo tep_draw_checkbox_field('newsletter', '1', 'selected') . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_NEWSLETTER_TEXT . '</span>': ''); ?></td>

 

 

but it does not work! :rolleyes:

Link to comment
Share on other sites

Looking at the html_output.php file in the includes/functions it would appear than you need to send the function a third value, in this case 'true' (without the apostrophes). I did this and sure enough the newletter checkbox was automatically checked on my register page.

 

Looking at your code this is also what you have done. In fact replacing the entire line in my code with yours achieved your desired effect so I'm not sure why it doesn't work with you. Also, it's probably just my eyes, but the two lines you have shown as your alteration are exactly the same? EDIT : ah you've changed it :)

 

Maybe you have changed something in the html_output.php file? Mine is :

 

function tep_draw_checkbox_field($name, $value = '', $checked = false, $parameters = '') {

return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);

}

 

Sorry I can't be of more help.

Link to comment
Share on other sites

Looking at the html_output.php file in the includes/functions it would appear than you need to send the function a third value, in this case 'true' (without the apostrophes). I did this and sure enough the newletter checkbox was automatically checked on my register page.

 

Looking at your code this is also what you have done. In fact replacing the entire line in my code with yours achieved your desired effect so I'm not sure why it doesn't work with you. Also, it's probably just my eyes, but the two lines you have shown as your alteration are exactly the same? EDIT : ah you've changed it :)

 

Maybe you have changed something in the html_output.php file? Mine is :

 

function tep_draw_checkbox_field($name, $value = '', $checked = false, $parameters = '') {

return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);

}

 

Sorry I can't be of more help.

 

 

Thanks for trying to help! :thumbsup:

 

I think I have the same (here is what I have in the html_output.php):

 

 

////

// Output a form checkbox field

function tep_draw_checkbox_field($name, $value = '', $checked = false, $parameters = '') {

return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);

}

Link to comment
Share on other sites

Ok I've searched all the files for an instance of a checkbox being used to ask whether you want to receive the newsletter. Its in the create_account.php file only. Change the line in the create_account.php file to :

 

<td class="main"><?php echo tep_draw_checkbox_field2('newsletter', '1') . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_NEWSLETTER_TEXT . '</span>': ''); ?></td>

 

Then in the html_output.php file add the following under the existing tep_draw_checkbox_field function :

 

function tep_draw_checkbox_field2($name, $value = '', $checked = true, $parameters = '') {

return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);

}

 

See if this works :)

 

Ben

Link to comment
Share on other sites

Ok I've searched all the files for an instance of a checkbox being used to ask whether you want to receive the newsletter. Its in the create_account.php file only. Change the line in the create_account.php file to :

 

<td class="main"><?php echo tep_draw_checkbox_field2('newsletter', '1') . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_NEWSLETTER_TEXT . '</span>': ''); ?></td>

 

Then in the html_output.php file add the following under the existing tep_draw_checkbox_field function :

 

function tep_draw_checkbox_field2($name, $value = '', $checked = true, $parameters = '') {

return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);

}

 

See if this works :)

 

Ben

 

 

I got this:

 

Fatal error: Call to undefined function: tep_draw_checkbox_field() in /home/gourmet/public_html/shop/shopping_cart.php on line 113

Link to comment
Share on other sites

I got this:

 

Fatal error: Call to undefined function: tep_draw_checkbox_field() in /home/gourmet/public_html/shop/shopping_cart.php on line 113

 

Did you add the new one or just change the old one.. add it as a new one :)

Link to comment
Share on other sites

Did you add the new one or just change the old one.. add it as a new one :)

 

 

I wonder whether I'm doing it right? I have the following now:

 

In create_account.php:

 

<td class="main"><?php echo tep_draw_checkbox_field('newsletter', '1', 'true') . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_NEWSLETTER_TEXT . '</span>': ''); ?></td>

 

<td class="main"><?php echo tep_draw_checkbox_field2('newsletter', '1') . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_NEWSLETTER_TEXT . '</span>': ''); ?></td>

 

and in html_output.php:

 

////

// Output a form checkbox field

function tep_draw_checkbox_field($name, $value = '', $checked = false, $parameters = '') {

return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);

}

 

 

function tep_draw_checkbox_field2($name, $value = '', $checked = true, $parameters = '') {

return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);

}

 

 

The end result is that on the order page it has 'Options Newsletter:' only once and it is unchecked! :blink:

Link to comment
Share on other sites

I got to work! :rolleyes:

 

If someone runs into the same issues - here is what I have now:

 

in:

 

includes/functions/html_output.php:

 

 

////

// Output a form checkbox field

function tep_draw_checkbox_field($name, $value = '', $checked = true, $parameters = '') {

return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);

}

 

and in:

 

create_account.php:

 

<td class="main"><?php echo tep_draw_checkbox_field('newsletter', '1', 'true') . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_NEWSLETTER_TEXT . '</span>': ''); ?></td>

 

It works! It works! It works! :rolleyes:

 

Thanks again to everyone trying to help! :thumbsup:

Link to comment
Share on other sites

  • 1 month later...

I copied Allysin's changes and sure enough it checks the newsletter box but is also checks the 'remove from cart' box on the shopping cart so when a customer updates their cart it automatically empties the cart!

Please can anyone tell me how do you check the newsletter box without all other boxes being checked?

Link to comment
Share on other sites

For stock osc in catalog/includes/functions/html_output.php you should have this

// Output a selection field - alias function for tep_draw_checkbox_field() and tep_draw_radio_field()
 function tep_draw_selection_field($name, $type, $value = '', $checked = false, $parameters = '') {
$selection = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"';

if (tep_not_null($value)) $selection .= ' value="' . tep_output_string($value) . '"';

if ( ($checked == true) || ( isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) && ( ($GLOBALS[$name] == 'on') || (isset($value) && (stripslashes($GLOBALS[$name]) == $value)) ) ) ) {
  $selection .= ' CHECKED';
}

if (tep_not_null($parameters)) $selection .= ' ' . $parameters;

$selection .= '>';

return $selection;
 }

////
// Output a form checkbox field
 function tep_draw_checkbox_field($name, $value = '', $checked = false, $parameters = '') {
return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);
 }

////
// Output a form radio field
 function tep_draw_radio_field($name, $value = '', $checked = false, $parameters = '') {
return tep_draw_selection_field($name, 'radio', $value, $checked, $parameters);
 }

 

In catalog create_account.php change

				<td class="main"><?php echo tep_draw_checkbox_field('newsletter', '1') . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_NEWSLETTER_TEXT . '</span>': ''); ?></td>

 

To

				<td class="main"><?php echo tep_draw_checkbox_field('newsletter', '1', 'true') . ' ' . (tep_not_null(ENTRY_NEWSLETTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_NEWSLETTER_TEXT . '</span>': ''); ?></td>

 

I have alsu used 'checked' and 'selected'. They all work ok for me.

Link to comment
Share on other sites

Thank you, I already had the most of the code, and only needed to add 'true' - just like I expected.

the "does not work" messages must have been posted by users of older version of osC.

-works fine

 

Thank You

Link to comment
Share on other sites

  • 2 years later...

Just a note of caution: some customers will be very irritated by being automatically subscribed to your newsletter, and may report you as a spammer. Even though you still have a checkbox that they can uncheck ("opt out"), they may overlook it. That's why the checkbox was defaulting to unchecked ("opt in"). If you want to check it by default, please do the following two things:

 

1) don't "hide" the checked box -- make it very clear and obvious that they will receive a newsletter unless they uncheck it

2) in each newsletter, near the top give clear instructions on how to unsubscribe (and resubscribe if they change their minds)

Link to comment
Share on other sites

  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...