views:

43

answers:

2

On my site, a user gets email notifications when someone comments on their profile, or comments on their blog etc...I have made a email settings page that has checkboxes to allow the user to decide to receive emails or not.

This is what I am wrapping around the email notification code chunck for the pages that have the php mail:

    <?php if(isset($_POST['email_toggle']) && $_POST['email_toggle'] == 'true') { if(isset($_POST['commentProfileSubmit']) && $auth) {

     $query etc
     $to = etc


  }
}

My question is what do I put on the email settings script that has the actual check boxes to make them stay checked or unchecked once you submit your settings? Another words what do I put in the if(isset portion to implement the changes?

if(isset($_POST['email_toggle']) && $_POST['email_toggle'] == 'true') {

/* what do I put here? */

header("Location: Profile.php?id=" . $auth->id);
 mysql_query($query,$connection);

/* input/check boxes and submit button */

<tr>
 <td class="email_check">
  <input type="checkbox" name="email_toggle" value="true" checked="checked" /> Receive email Notifications When Someone Answers A Question You've Answered
 </td>
</tr>
<tr>
 <td>
  <input style="margin:10px 0px 0px 10px;" class="submit" type="submit" name="email_toggle" value="Save Settings" />
 </td>
</tr>
}
+1  A: 

I am not sure if this is what you mean, but you have to get the settings of user from the database and store them in a variable, e.g. $receive_email.

Then you do in your HTML:

<td class="email_check">
   <input type="checkbox" 
          name="email_toggle" 
          value="true" <?php if($receive_email) echo 'checked="checked"' ?> />
</td>
Felix Kling
+2  A: 

I'm not sure what you mean. You can do it as Felix suggests and keep it for the session. But if you need it to be permanently stored (I think you do) you need to save it to your database and then your 'e-mail preferences' page will query to see what checkboxes are set by the user and produce checked or unchecked checkboxes in the XHTML.

C. Papadopoulos
Just to clarify my answer: With *get the settings of user* I meant to get them from the database. I thought the OP already uses a database for storing the settings as in the code are already mysql_function. Maybe I got it wrong....
Felix Kling