php checkbox

They have: 32 posts

Joined: Jun 2009

I have an exisitng php script (open source), but am not up to scratch with the subject yet (will be taking a course on the subject in the near future).

I wish to simply add a checkbox to the script so that the result will be posted via email - the checkbox will be a very basic one:

Tick here to join mailing list

I've scoured the web and get one to work, but only to post results on screen using echo command.

Please help

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

In order to help you, we would need to know what the current script is doing (is it already e-mailing someone else, and you just need to add a recipient, etc). Since it's open source, can you list which one it is?

Basically in a nutshell, assuming you are already collecting the needed information, add the checkbox:

<input type="checkbox" name="chkSubscribe" value="join" id="chkSubscribe">
<label for="chkSubscribe">Tick here to join mailing list</label>

Then in the PHP, do a check for that value being set:

if ($_POST['chkSubscribe']=='join') {
   // Code to e-mail you their info
   // (see http://us.php.net/manual/en/function.mail.php for some samples)
}

-Greg

He has: 53 posts

Joined: Jun 2010

Code for simple HTML Script :->

Code for simple PHP Script :->

if ($_POST['chk_box']=='enter')
{
// Code which you want to execute.
}
Explanation here $_POST[] is an global variable, and $_POST['chk_box'] means it retrieve the value of check box on client side then check it at server side by value enter.
actually it $_POST[] create an array

Like array
{
$_POST['chk_box'] is equivalent to $_POST[index of array 0] = value i.e. enter
}

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.