emailForm

5 posts by 3 authors in: Forums > CMS Builder
Last Post: September 22, 2014   (RSS)

By Toledoh - September 18, 2014

Hi Guys,

Just using a standard emailForm.php (attached), but I want to add a "rating" question - so a group of radio buttons.

How is the best way of implementing this, and making answering one from the group mandatory?

Cheers,

Tim (toledoh.com.au)
Attachments:

emailform.php 3K

By gregThomas - September 19, 2014

Hey Tim,

I've attached an updated copy of the e-mail form, here is what's new:

I've added the following HTML:

  <td>
    <input <?php checkedIf(@$_REQUEST['rating'], '5'); ?> type="radio" name="rating" value="5" />Amazing</td>
    <input <?php checkedIf(@$_REQUEST['rating'], '4'); ?> type="radio" name="rating" value="4" />Good</td>
    <input <?php checkedIf(@$_REQUEST['rating'], '3'); ?> type="radio" name="rating" value="3" />OK</td>
    <input <?php checkedIf(@$_REQUEST['rating'], '2'); ?> type="radio" name="rating" value="2" />Bad</td>
    <input <?php checkedIf(@$_REQUEST['rating'], '1'); ?> type="radio" name="rating" value="1" />Never Again.</td>
 </tr>

As the radio buttons all have the same name, it will only be possible for the user to select one value. The checkedIf function will ensure the correct radio button is selected if the user submits the form and there are errors.

Checking if the user has selected the appropriate radio button can be done like this:

if (!@$_REQUEST['rating'])                 { $errorsAndAlerts .= "You must select a rating!<br/>\n"; }

If no rating is selected, then the e-mail won't be sent, as an error will be added to errorsAndAlerts.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com
Attachments:

emailform.php 4K

By Toledoh - September 19, 2014

Brilliant!  Thanks!

Cheers,

Tim (toledoh.com.au)

By Jesus - September 20, 2014

I'll love to implement a comments/rating system and something like this could be a great start.

I want to have: Name/Email/Comments/Ratings on my table, and it will be great to receive an email but also, to insert this on my comments/rating table, so I can display comments and get an average rate from all rates received.

How hard will it be to implement something like this? (using this as a base), thanks in advance for sharing.

Jesus