Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDanny Massa
27,856 PointsSend <a href=”#”> through checkbox value
Is it possible to send an HTML ancor tag through a checkbox value?
e.g. < input type="checkbox" name="item_offer[]" value="< a href="#" >iPad Air 32GB< /a >" >
Then that value be send through email message as a link? That way when the user receives an email he can click the link and take them to the page?
7 Answers
Jeremy Germenis
29,854 PointsInstead of trying to pass the href tag you can do something like take the value="iPad Air 32GB" and have php add the href tags to the value.
Example: $link = '<a href="#">' . $_POST[item_offer] . '</a>';
Danny Massa
27,856 PointsSweet! Thanks for the reply
I have the href in a while loop
<?php if ( is_user_logged_in() && have_posts() ) : ?>
<label><?php printf( __( "%s's Item's", APP_TD ), $display_user_name ); ?></label><br>
<?php
while( have_posts() ) : the_post(); $i++; ?>
<input type="checkbox" name="item_offer" id="item_offer" value="<?php the_title(); ?>"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endwhile; ?>
<?php else : ?>
<p class="text-center"><?php _e( 'Please login to select your items.', APP_TD ); ?></p>
<?php endif;?>
if the client selects 2 checkboxes or 3 checkboxes then there are 3 href links - how do i assign them according to each checkbox they selected
Jeremy Germenis
29,854 PointsYou would set the attribute name to "item_offer[]" which will create an array of item_offers's. You can then traverse through $_POST[item_offers] as an array with a foreach loop.
Danny Massa
27,856 Pointsawesome! Thank you so much jeremy, anyway you can show me an example? :)
Jeremy Germenis
29,854 Points<input name="item_offer[]" value ="http://something.com" />
<input name="item_offer[]" value ="http://something-else.com" />
foreach ($_POST['item_offer'] as $value ) {
echo '<a href="' . $value . '">click here for awesome</a>';
}
Danny Massa
27,856 PointsHmmm, I'm having trouble cause I have
the_title(); - (title of the item in persons inventory) and the_permalink(); - (the link to that item)
the value of the checkbox is the item name e.g. 42" samsung plasma and emailed but I want the the link aswell in the email so ppl can just click the direct link to the item
I can't add the_permalink(); in the value of the checkbox with a href with the title though that would be easy done
<input type="checkbox" name="item_offer[]" value="<?php the_title(); ?>"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
So i need the link and the name - please help me :(
Jeremy Germenis
29,854 PointsThe title would depend on your structure.
- You could "explode" the value -> value="example.com+MyTitle" (google search "php explode")
- If your products are in a database you could query the db for the title
- If you are using jQuery you could add another attribute
thomascawthorn
22,986 Pointsthomascawthorn
22,986 PointsJust to expand a little more, you'll want to do this in the form processing script - wherever that may be. When the form is submitted the post-processing script can wrap the checkbox value just like Jeremy Germenis suggested and save it in a variable. When you build the body of the email, you can then concatenate the whole link element within the body - making sure you also add spaces either side of the variable! :-)