emailForm

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

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

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

Hi Jesus, 

It would be fairly straight forward to add this feature. CMSB comes with a function called mysql_insert. This allows you to add data to a CMSB table if you have the viewer functions included in the page. Here is how you would use it:

mysql_insert($sectionName, $arrayOfData);

So the function has to variables, the CMS Builder section you're adding the data to, and an array of data to insert, with the fields as the keys, and the values as the values. Here is how you might use it for this e-mail form:

   $insertData = array();
   $insertData['fullname'] = $_REQUEST['fullname'];
   $insertData['email']    = $_REQUEST['email'];
   $insertData['message']  = $_REQUEST['message'];
   $insertData['rating']   = $_REQUEST['rating'];

   mysql_insert('email_messages', $insertData, true);

The true that has been added as the third element to the function tells it that if it doesn't have a value for a particular field (for example, created date). Then it should enter an empty value.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com