Radio Buttons & Check Boxes

6 replies · opened Nov 21, 2016

GgingernutcreativeNov 21, 2016

Hello there

I have a form which aside from the basic items you have on the prebuilt forms has a series of checkboxes and radio buttons, I have found the page that has the styles etc for these elements and copied them to my form page . . HOWEVER what do I need to add to the PHP file to get the results of these questions/options returned in the email ?

Cheers

SSemicolon WebSTAFFNov 21, 2016

Hello,

You can get the Value of the Form Elements in PHP by the name Attribute of the Form Element. So if a Form Element's name is defined as template-contactform-name in the HTML, then you can simply get the value in PHP by the following code:

$_POST['template-contactform-name']

This will Definitely work fine. Hope this Helps!

Do let us know if we can help you with anything else or if you find any further issues with Canvas.

GgingernutcreativeNov 21, 2016

Hello there . .

I have managed to get the RADIO set working just tip top . . struggling with the CHECKBOX

(THIS WORKS OK)
$question1 = isset( $_POST['radio-group-1'] ) ? $_POST['radio-group-1'] : '';

(THIS WORKS OK)
$question2 = isset( $_POST['template-contactform-question2'] ) ? $_POST['template-contactform-question2'] : '';

(THIS IS MY ISSUE where I have numerous options, I get 1 selection returned on the email not all checked <--see question 3 below -->)
$question3 = isset( $_POST['checkbox-1'] ) ? $_POST['checkbox-1'] : '';

<!-- question 3 -->

<div class="col_full">
<div><label for="template-contactform-question3">What do you think is currently lacking in the local housing market? <small>*</small></label>
</div>
</div>
<div>
<input id="checkbox-1" class="checkbox-style" name="checkbox-1" type="checkbox" value="Homes for first time buyers">
<label for="checkbox-1" class="checkbox-style-2-label">Homes for first time buyers</label>
</div>
<div>
<input id="checkbox-2" class="checkbox-style" name="checkbox-2" type="checkbox" value="Homes for older people">
<label for="checkbox-2" class="checkbox-style-2-label">Homes for older people</label>
</div>
<div>
<input id="checkbox-3" class="checkbox-style" name="checkbox-3" type="checkbox" value="Family housing">
<label for="checkbox-3" class="checkbox-style-2-label">Family housing</label>
</div>
<div>
<input id="checkbox-4" class="checkbox-style" name="checkbox-4" type="checkbox" value="Affordable housing">
<label for="checkbox-4" class="checkbox-style-2-label">Affordable housing</label>
</div>
<div>
<input id="checkbox-5" class="checkbox-style" name="checkbox-5" type="checkbox" value="Large executive homes">
<label for="checkbox-5" class="checkbox-style-2-label">Large executive homes</label>
</div>
<div>
<input id="checkbox-6" class="checkbox-style" name="checkbox-6" type="checkbox" value="Smaller homes">
<label for="checkbox-6" class="checkbox-style-2-label">Smaller homes</label>
</div>
<div>
<input id="checkbox-7" class="checkbox-style" name="checkbox-7" type="checkbox" value="Other">
<label for="checkbox-7" class="checkbox-style-2-label">Other</label>
</div>
<br>

<!-- question 3 END -->

What gets inserted to the PHP line below as I'm pretty sure it isn't 'checkbox-1' :
$question3 = isset( $_POST['checkbox-1'] ) ? $_POST['checkbox-1'] : '';

:-(

GgingernutcreativeNov 21, 2016

Hello there . .

I have managed to get the RADIO set working just tip top . . struggling with the CHECKBOX

(THIS WORKS OK)
$question1 = isset( $_POST[‘radio-group-1’] ) ? $_POST[‘radio-group-1’] : ”;

(THIS WORKS OK)
$question2 = isset( $_POST[‘template-contactform-question2’] ) ? $_POST[‘template-contactform-question2’] : ”;

(THIS IS MY ISSUE where I have numerous options, I get 1 selection returned on the email not all checked <–see question 3 below –>)
$question3 = isset( $_POST[‘checkbox-1’] ) ? $_POST[‘checkbox-1’] : ”;

<!– question 3 –>

<div class=”col_full”>
<div><label for=”template-contactform-question3″>What do you think is currently lacking in the local housing market? <small>*</small></label>
</div>
</div>
<div>
<input id=”checkbox-1″ class=”checkbox-style” name=”checkbox-1″ type=”checkbox” value=”Homes for first time buyers”>
<label for=”checkbox-1″ class=”checkbox-style-2-label”>Homes for first time buyers</label>
</div>
<div>
<input id=”checkbox-2″ class=”checkbox-style” name=”checkbox-2″ type=”checkbox” value=”Homes for older people”>
<label for=”checkbox-2″ class=”checkbox-style-2-label”>Homes for older people</label>
</div>
<div>
<input id=”checkbox-3″ class=”checkbox-style” name=”checkbox-3″ type=”checkbox” value=”Family housing”>
<label for=”checkbox-3″ class=”checkbox-style-2-label”>Family housing</label>
</div>
<div>
<input id=”checkbox-4″ class=”checkbox-style” name=”checkbox-4″ type=”checkbox” value=”Affordable housing”>
<label for=”checkbox-4″ class=”checkbox-style-2-label”>Affordable housing</label>
</div>
<div>
<input id=”checkbox-5″ class=”checkbox-style” name=”checkbox-5″ type=”checkbox” value=”Large executive homes”>
<label for=”checkbox-5″ class=”checkbox-style-2-label”>Large executive homes</label>
</div>
<div>
<input id=”checkbox-6″ class=”checkbox-style” name=”checkbox-6″ type=”checkbox” value=”Smaller homes”>
<label for=”checkbox-6″ class=”checkbox-style-2-label”>Smaller homes</label>
</div>
<div>
<input id=”checkbox-7″ class=”checkbox-style” name=”checkbox-7″ type=”checkbox” value=”Other”>
<label for=”checkbox-7″ class=”checkbox-style-2-label”>Other</label>
</div>
<br>

<!– question 3 END –>

What gets inserted to the PHP line below as I’m pretty sure it isn’t ‘checkbox-1’ :
$question3 = isset( $_POST[‘checkbox-1’] ) ? $_POST[‘checkbox-1’] : ”;

?

GgingernutcreativeNov 22, 2016

Hello there . .

I have managed to get the RADIO set working just tip top . . struggling with the CHECKBOX

(THIS WORKS OK)
$question1 = isset( $_POST[‘radio-group-1’] ) ? $_POST[‘radio-group-1’] : ”;

(THIS WORKS OK)
$question2 = isset( $_POST[‘template-contactform-question2’] ) ? $_POST[‘template-contactform-question2’] : ”;

(THIS IS MY ISSUE where I have numerous options, I get 1 selection returned on the email not all checked <–see question 3 below –>)
$question3 = isset( $_POST[‘checkbox-1’] ) ? $_POST[‘checkbox-1’] : ”;

<!– question 3 –>

<div class=”col_full”>
<div><label for=”template-contactform-question3″>What do you think is currently lacking in the local housing market? <small>*</small></label>
</div>
</div>
<div>
<input id=”checkbox-1″ class=”checkbox-style” name=”checkbox-1″ type=”checkbox” value=”Homes for first time buyers”>
<label for=”checkbox-1″ class=”checkbox-style-2-label”>Homes for first time buyers</label>
</div>
<div>
<input id=”checkbox-2″ class=”checkbox-style” name=”checkbox-2″ type=”checkbox” value=”Homes for older people”>
<label for=”checkbox-2″ class=”checkbox-style-2-label”>Homes for older people</label>
</div>
<div>
<input id=”checkbox-3″ class=”checkbox-style” name=”checkbox-3″ type=”checkbox” value=”Family housing”>
<label for=”checkbox-3″ class=”checkbox-style-2-label”>Family housing</label>
</div>
<div>
<input id=”checkbox-4″ class=”checkbox-style” name=”checkbox-4″ type=”checkbox” value=”Affordable housing”>
<label for=”checkbox-4″ class=”checkbox-style-2-label”>Affordable housing</label>
</div>
<div>
<input id=”checkbox-5″ class=”checkbox-style” name=”checkbox-5″ type=”checkbox” value=”Large executive homes”>
<label for=”checkbox-5″ class=”checkbox-style-2-label”>Large executive homes</label>
</div>
<div>
<input id=”checkbox-6″ class=”checkbox-style” name=”checkbox-6″ type=”checkbox” value=”Smaller homes”>
<label for=”checkbox-6″ class=”checkbox-style-2-label”>Smaller homes</label>
</div>
<div>
<input id=”checkbox-7″ class=”checkbox-style” name=”checkbox-7″ type=”checkbox” value=”Other”>
<label for=”checkbox-7″ class=”checkbox-style-2-label”>Other</label>
</div>
<br>

<!– question 3 END –>

What gets inserted to the PHP line below as I’m pretty sure it isn’t ‘checkbox-1’ :
$question3 = isset( $_POST[‘checkbox-1’] ) ? $_POST[‘checkbox-1’] : ”;

GgingernutcreativeNov 22, 2016

OK I have posted a couple of times yet no response, I see someone is replying to posts as there have now been 3 later than mine and they have been answered, I'm not sure if I'm being ignored but I could really do with this issue being resolved as the site needs to be LIVE close of play today !!!!

You can see my original post above (this is after the post 'Radio Buttons & Checkboxes that was answered but not in its entirety).

I will attached both files below PLEASE HELP.

P.

SSemicolon WebSTAFFNov 24, 2016

Hello,

We Really Apologize about the Delay! We have checked out your Issue and understand your issue regarding this. If you are using Checkboxes, then you will need to use arrays to get the values of all the Checkboxes in the PHP.

Consider using the following HTML Code for the Checkboxes:


Your Value

Please notice the name Attribute in the above code: name="checkbox[]". This stores the Values of all the Checkboxes in the array: checkbox.

Now, your PHP Code will be:

$checkbox = isset( $_POST['checkbox'] ) ? $_POST['checkbox'] : '';

if( is_array( $checkbox ) ) {
	$checkbox = !empty($checkbox) ? "Checkbox: " . implode( ', ', $checkbox ) . "

" : '';
} else {
	$checkbox = isset($checkbox) ? "Checkbox: $checkbox

" : '';
}

This will definitely work fine. Let us know if we can help you with anything else or if you find any further issues.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard