Log in

View Full Version : Required Attribute for Select Option - For PHP WordPress File



claireym
08-27-2014, 11:07 PM
Hi there,

I hope I am posting in the correct forum here as I am working on a WordPress site so I am working between PHP and HTML.

I sell cards and I am currently trying to get them online. You can see the link here: http:/little-letters.com/?wpsc-product=baby-blue-baby-boy-thankyou-card

My problem is I don't know how to make the dropdown boxes a requirement before the form can be submitted. At the moment you can select no options and it still adds the product to the cart.

I have been looking at this part of the PHP file within WordPress - perhaps it could be another file? I am more used to HTML and CSS.


<?php
/**
* Form data
*/
?>
<div class="section_rt">
<form class="product_form" enctype="multipart/form-data" action="<?php echo esc_url( wpsc_this_page_url() ); ?>" method="post" name="1" id="product_<?php echo wpsc_the_product_id(); ?>">
<?php do_action ( 'wpsc_product_form_fields_begin' ); ?>
<?php if ( wpsc_product_has_personal_text() ) : ?>
<fieldset class="custom_text">
<legend style="font-family:Georgia; font-style: italic; font-size: 18px;"><?php _e( 'Your Info', 'wpsc' ); ?></legend>
<p style="font-family:Trebuchet MS; font-size: 12px;"><?php _e( 'Name, DOB, Weight etc', 'wpsc' ); ?></p>
<textarea cols='55' rows='5' placeholder="Name, Date of Birth, Weight" style='width:130px; resize: none; margin-bottom:20px;' name="custom_text"></textarea>
</fieldset>
<?php endif; ?>

<?php if ( wpsc_product_has_supplied_file() ) : ?>

<fieldset class="custom_file">
<legend style="font-family:Georgia; font-style: italic; font-size: 18px;"><?php _e( 'Your Photo', 'wpsc' ); ?></legend>
<p style="font-family:Trebuchet MS; font-size: 12px;"><?php _e( 'Choose a photo', 'wpsc' ); ?></p>
<input type="file" name="custom_file" />
</fieldset>
<?php endif; ?>
<?php /** the variation group HTML and loop */?>
<?php if (wpsc_have_variation_groups()) { ?>
<fieldset style="border:0;"><legend style="font-family:Georgia; font-style: italic; font-size: 19px; color:#404040;"><?php _e('Options', 'wpsc'); ?></legend>
<div class="wpsc_variation_forms">
<table style="border:0;">
<?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
<tr><td class="col1" style="border:0;"><label style="font-family:Trebuchet MS; font-size: 12px;" for="<?php echo wpsc_vargrp_form_id(); ?>"><?php echo wpsc_the_vargrp_name(); ?>:</label></td>
<?php /** the variation HTML and loop */?>
<td class="col2"><select style="font-size:12px; width:120px;" class="wpsc_select_variation" name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>">
<?php while (wpsc_have_variations()) : wpsc_the_variation(); ?>
<option style="font-family:Trebuchet MS; font-size: 12px; padding:10px;" value="<?php echo wpsc_the_variation_id(); ?>" <?php echo wpsc_the_variation_out_of_stock(); ?>><?php echo wpsc_the_variation_name(); ?></option>
<?php endwhile; ?>
</select></td></tr>
<?php endwhile; ?>
</table>
</div><!--close wpsc_variation_forms-->
</fieldset>


If anyone has any ideas I would greatly appreciate it! I have tried adding in "required" as you would do with HTML but to no avail.

Thanks in advance!

claireym
09-02-2014, 04:05 PM
Anyone any ideas?