1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Sign up form-optional checkbox to save email in a TXT file

Discussion in 'Programming' started by HRA, Jan 26, 2015.

  1. #1
    Hi,

    Right now my sign up form looks like this:
    http://i58.tinypic.com/s0zekj.jpg

    I want to make it like this:
    http://i61.tinypic.com/zj6tc5.jpg

    Obviously I can make the design changes. Problem is I don't know how to make it function as I need.

    User will enter his Username, email, password. Accepting to Terms is compulsory.
    IF he checks "Tell me about Contests", then Click Submit, then the email he entered should be saved in a txt file in the server (one email per line).
    If he doesn't check it, then his email address will not be saved in a txt file.
    I only need the email address. I don't need username, password.

    My objective is, I need to collect email addresses to send them updates, news, notifications about contests etc. This way I will get the email addresses of people who are willing to receive those emails.

    My site is based on wordpress. So if someone can provide a sample code in php, I think I can substitute it with my site code.

    Not sure if it matter, but I have a referral signup system, email confirmation/ account activation system in place.

    Thanks
     
    HRA, Jan 26, 2015 IP
  2. Equaite

    Equaite Active Member

    Messages:
    128
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    Digital Goods:
    1
    #2
    This is relatively simple;

    Name your new checkbox notify, for example
    <input type="checkbox" name="notify" value="1" />
    Code (markup):
    In your existing PHP code that handles the form, apply this somewhere that it will execute with the successful form submission;
    
    if ((bool) (int) $_REQUEST['notify']) {
        file_put_contents('emails.txt', "\n" . $_REQUEST['email'], FILE_APPEND); // replace this with the actual input name of your email field
    }
    
    PHP:
    Make sure you create a file called emails.txt that is WRITABLE
     
    Equaite, Jan 27, 2015 IP
  3. HRA

    HRA Active Member

    Messages:
    314
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #3
    This is frustrating that I can't even get such a simple thing to work WITH help.
    This is my checkbox:
    <input type="checkbox" name="notify" value="1" />
    <label>Tell me about contests</label>
    PHP:
    This is my Email field code:
    <label for="your_email">Email</label>
    <input name="your_email_for_pub_ad" id="ad-reg-email" />
    PHP:
    This is how I added your code:
    if ((bool) (int) $_REQUEST['notify']) {
        file_put_contents('emails.txt', "\n" . $_REQUEST['your_email_for_pub_ad'], FILE_APPEND); // replace this with the actual input name of your email field
    }
    
    PHP:
    There is a ONE file with all functions (I think) in a separate folder (sub folder of my theme folder), that is where I added "your" code.
    My checkbox code and email field code is in a different folder (my theme folder)

    I added emails.txt to both locations. CHMOD is to 777.

    Any idea why its not working?

    Thanks
     
    HRA, Jan 27, 2015 IP
  4. Equaite

    Equaite Active Member

    Messages:
    128
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    Digital Goods:
    1
    #4
    Are you getting any error? I am assuming that the PHP code is not being executed if you aren't receiving errors, unless you have error displaying turned off
     
    Equaite, Jan 27, 2015 IP
  5. HRA

    HRA Active Member

    Messages:
    314
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #5
    display_errors is turned on.
    Do I need to turn display_startup_errors on too?

    If I provide you access, do you have time to take a look?

    Thanks
     
    HRA, Jan 27, 2015 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    The point is - the input with the checkbox is probably in an existing form, right? That form will send it's information to a file, or to itself, depending on how it's coded. So, what does it say in the action-attribute on the fom you placed the checkbox in?
     
    PoPSiCLe, Jan 28, 2015 IP
  7. HRA

    HRA Active Member

    Messages:
    314
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #7
    This is what I see:
    <form name="registration_for_ad" id="registration-for-ad" method="post" action="">
    
    PHP:
    Thanks
     
    HRA, Jan 28, 2015 IP
  8. Equaite

    Equaite Active Member

    Messages:
    128
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    Digital Goods:
    1
    #8
    What I would recommend, is finding a reference to the corresponding input fields of that form, in your PHP code. Basically find out where in your PHP code the registration is being processed, and apply my PHP snippet to that area.

    I would be happy to take a look for you, but the idea here is to help you learn and understand what is going on. You're on the right track, just need to do some digging. :)

    You could always download Sublime Text, and use it's "Find in Folder" feature, to pinpoint the code.
     
    Equaite, Jan 28, 2015 IP
  9. HRA

    HRA Active Member

    Messages:
    314
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #9
    Yeah I want to understand. So I'll try that tool you suggested and if I still can't figure it out I will let you know and you can take a look.
    Thanks
     
    HRA, Jan 28, 2015 IP
  10. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #10
    Okay - then it's one of two - if that form is processed via AJAX, then it doesn't really need an action-property, same if it's processed within the same file - it's either one. So either the processing is in the file itself, or you need to go looking for a javascript-file that processes the form.
     
    PoPSiCLe, Jan 29, 2015 IP
  11. Equaite

    Equaite Active Member

    Messages:
    128
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    Digital Goods:
    1
    #11
    @PoPSiCLe this isn't necessarily true. A blank action would target the current URL, but that doesn't mean it's a single page PHP script. It could be a bootstrapped application, and the code that handles that form could be in any number of locations.
     
    Equaite, Jan 29, 2015 IP
  12. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #12
    That is true, but in that case, most likely there is an include-script somewhere - which I of course should have mentioned. Regardless, I doubt this is the most advanced WP-plugin out there, and it's probably relatively simple to figure out.
     
    PoPSiCLe, Jan 29, 2015 IP