The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Handling certain html form elements/check up
ASDFGHJKL
post Jun 9 2014, 06:19 PM
Post #1





Group: Members
Posts: 3
Joined: 9-June 14
Member No.: 21,072



I am trying to make a handler for this form , it involves checkboxes, and dropdown menus. I have looked on different sites, but couldn't find anything to helpful. So my question is: How can I set up a PHP script to simply send this to email, each response separated by a common, or more specifically, how to handle dropdown menus and checkboxes with a PHP script. Any examples or helpful insight would be appreciated.I want to keep it simple, as I do not currently know PHP ,and do not want to do anything complex, but I want full control so I do not want to use something like google forms. I have been trying to do this for a while, with no success. If anyone can help me, it would make my day.

Here is the code for reference( I have kept it simple to simplify things)
<form action="" method="get"><fieldset><legend>Demographics....</legend>
First Name: <input type="text" name="name"><br/>
Tag Class: <input type ="text" name="tag"><br/></fieldset>
<fieldset>
<legend>Social Media</legend>
<label>Selects which you have:</label><br/>
Facebook:<input type= "checkbox" name="FB" value="FB"/><br/>
Twitter: <input type= "checkbox" name="TWEET" value="TWEET"/><br/>
Instagram:<input type= "checkbox" name="INSTA" value="INSTA"/><br/>
Pinterest:<input type= "checkbox" name="PIN" value="PIN"/><br/>
Flicker:<input type= "checkbox" name="FLICK" value="FLICK"/><br/>
LinkedIn:<input type= "checkbox" name="LINK" value="LINK"/><br/>
MySpace:<input type= "checkbox" name="SPACE" value="SPACE"/><br/>
Which is your most used?
<select id="social">
<option>Facebook</option>
<option>Twitter</option>
<option>Instagram</option>
<option>Pinterest</option>
<option>Flicker</option>
<option>LinkedIn</option>
<option>MySpace</option>

</select>


<br/> How much do you use this most used?<select id="rate">
<option>10+ times per day</option>
<option>8-9 times per day</option>
<option>6-7 times per day</option>
<option>4-5 times per day</option>
<option>2-3 times per day</option>
<option>Once a day</option>
<option>3-6 times per week</option>
<option>1-3 times per week</option>
<option>rarely</option><br/>

UPDATE HERE IS THE PHP CODE I HAVE TRIED, I got up to the checkboxes, but I am now confused as to how to send the mail, and the scroll menu.I do not really know where to go from here:
<?php
$name = $_POST['name']
$tag = $_POST['tag']
$FB = $_POST['FB'];
if ($FB != 'Yes') {
$FB= 'No';
}
$TWEET = $_POST['TWEET'];
if ($TWEET != 'Yes') {
$TWEET = 'No';
}
$INSTA = $_POST['INSTA'];
if ($INSTA != 'Yes') {
$INSTA = 'No';
}


$PIN = $_POST['PIN'];
if ($PIN != 'Yes') {
$PIN = 'No';
}
$FLICK = $_POST['FLICK'];
if ($FLICK != 'Yes') {
$FLICK = 'No';
}

$LINK = $_POST['LINK'];
if ($LINK != 'Yes') {
$LINK = 'No';
}
$SPACE = $_POST['SPACE'];
if ($SPACE != 'Yes') {
$SPACE = 'No';
}

Thanks a lot for reading my post and with my simple questions. I apologise for the sloppy organization of my code, and I understand it may be harder to read.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies(1 - 4)
Christian J
post Jun 10 2014, 08:11 AM
Post #2


.
********

Group: WDG Moderators
Posts: 8,256
Joined: 10-August 06
Member No.: 7



QUOTE(ASDFGHJKL @ Jun 10 2014, 01:19 AM) *

How can I set up a PHP script to simply send this to email

Use the http://php.net/manual/en/function.mail.php function. Sending mail can be fragile, so pay attention to details.

QUOTE
or more specifically, how to handle dropdown menus and checkboxes with a PHP script.

See http://php.net/manual/en/tutorial.forms.php for the basics.

QUOTE
<form action="" method="get">

You probably want METHOD=POST for this, especially since the PHP script uses $_POST variables (METHOD=GET puts all the form data in the URL querystring, and uses $_GET in the script). See also http://www.php.net/manual/en/language.variables.external.php

QUOTE
<select id="social">

The PHP script needs NAME attributes for form fields. In the case of dropdown menus, only the SELECT element uses a NAME attribute (not the individual OPTION elements).

QUOTE
<option>Facebook</option>

Consider using VALUE attributes for the OPTION elements (it's not mandatory, but may simplify the PHP script).

QUOTE
if ($FB != 'Yes')

The above checks if the value of $FB is not "Yes", but in the HTML you use value="FB" so it will never be "Yes"...
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
ASDFGHJKL
post Jun 10 2014, 06:27 PM
Post #3





Group: Members
Posts: 3
Joined: 9-June 14
Member No.: 21,072



QUOTE(Christian J @ Jun 10 2014, 08:11 AM) *

QUOTE(ASDFGHJKL @ Jun 10 2014, 01:19 AM) *

How can I set up a PHP script to simply send this to email

Use the http://php.net/manual/en/function.mail.php function. Sending mail can be fragile, so pay attention to details.

QUOTE
or more specifically, how to handle dropdown menus and checkboxes with a PHP script.

See http://php.net/manual/en/tutorial.forms.php for the basics.

QUOTE
<form action="" method="get">

You probably want METHOD=POST for this, especially since the PHP script uses $_POST variables (METHOD=GET puts all the form data in the URL querystring, and uses $_GET in the script). See also http://www.php.net/manual/en/language.variables.external.php

QUOTE
<select id="social">

The PHP script needs NAME attributes for form fields. In the case of dropdown menus, only the SELECT element uses a NAME attribute (not the individual OPTION elements).

QUOTE
<option>Facebook</option>

Consider using VALUE attributes for the OPTION elements (it's not mandatory, but may simplify the PHP script).

QUOTE
if ($FB != 'Yes')

The above checks if the value of $FB is not "Yes", but in the HTML you use value="FB" so it will never be "Yes"...

SO I should change FB value to no? Thanks for the help! I am going to look at those links, and throw something together, if it doesn't work, I will post it here, thanks though
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 10 2014, 07:02 PM
Post #4


.
********

Group: WDG Moderators
Posts: 8,256
Joined: 10-August 06
Member No.: 7



QUOTE(ASDFGHJKL @ Jun 11 2014, 01:27 AM) *

SO I should change FB value to no?

Well, note that e.g. $_POST['FB'] doesn't exist unless the user has ticked that checkbox, and if it doesn't exist there's no value to check... I'd probably use http://php.net/manual/en/function.isset.php to see if the variable exists, in which case the actual value of the checkbox doesn't matter. Instead you might create the email body content like this:

CODE
$message="Social media:\n\n";

if (isset($_POST['FB'])) {
$message.="Facebook\n";
}

if (isset($_POST['TWEET'])) {
$message.="Twitter\n";
}

//...etc

(The .= operator adds more to the existing $message value, while each \n adds a newline in plain text emails.)

QUOTE
if it doesn't work, I will post it here, thanks though

Just ask away, and you're welcome...

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
ASDFGHJKL
post Jun 11 2014, 04:52 PM
Post #5





Group: Members
Posts: 3
Joined: 9-June 14
Member No.: 21,072



Oh my goodness, this is more complex then I thought, I will play around and post something in a couple of days after my finals.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 16th December 2019 - 02:07 AM