EzPortal - Portal Software for Forums

EzPortal - Made to Fit Your SMF Forum - Glad You Found Us!
+- +-

UserBox

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Recent Posts

Smiley missing in shoutbox 2.1.4 by hustreamload
July 26, 2023, 08:14:02 am

Re: Theme Select Box question? by Shades
March 15, 2023, 06:49:49 pm

Re: Theme Select Box question? by Shades
March 09, 2023, 02:09:24 pm

Re: Theme Select Box question? by Shades
March 09, 2023, 01:55:53 pm

Re: Theme Select Box question? by EzPortal
March 09, 2023, 01:47:42 pm

Re: Theme Select Box question? by Shades
March 09, 2023, 01:34:07 pm

Re: Theme Select Box question? by EzPortal
March 09, 2023, 12:20:17 pm

Re: Theme Select Box question? by EzPortal
March 02, 2023, 11:26:15 pm

+- HTML Menu


Sample HTML Block Usage - You May Custom Code it, as needed!

Recent Topics ezBlock

Smiley missing in shoutbox 2.1.4 by hustreamload
July 26, 2023, 08:14:02 am

Theme Select Box question? by Shades
March 15, 2023, 06:49:49 pm

Where is the facebook button color? by EzPortal
February 28, 2023, 06:45:09 pm

Display on Mobile - SMF 2.1.3 and EZ 5.5.2 by BugginIn
December 29, 2022, 04:07:13 pm

Blocks Help by Riggs1973
November 20, 2022, 12:59:30 pm

Surface ol lite theme release Free! by Steffen K.
November 18, 2022, 03:57:24 am

Undefined index: href by EzPortal
October 04, 2022, 08:49:59 pm

SMF-ezportal_column_5.cache): failed to open stream: No such file or directory by EzPortal
June 04, 2022, 11:40:13 am

Arcade block error: failed to open stream: No such file or directory by Shades
May 20, 2022, 02:47:13 pm

ezPortal 5.5 by EzPortal
May 20, 2022, 09:59:30 am

Author Topic: sign up form for ezBlocks  (Read 8922 times)

0 Members and 1 Guest are viewing this topic.

Offline NCSurfer

  • Posts: 7
  • Karma: 0
sign up form for ezBlocks
« on: February 27, 2012, 05:52:58 pm »
This was actually from another site that I thought I would try with my site using ezPortal. And it worked like a charm.

You can use it in a php block! Just make sure you fill out the correct info for the thankyou and forum post.

I have left all the credits where they were, no changes.

Code: [Select]

global $sourcedir, $ID_MEMBER, $context, $scripturl, $user_info, $db_prefix;

// Generic Application Form
// URL: http://www.tinyportal.net/index.php?topic=29670.msg236779#msg236779
// Date: 30 November 2009

// Guests can't fill out the form
if ($ID_MEMBER == 0)
    echo 'You must be logged in before you can apply.';
else {

   require_once($sourcedir . '/Subs.php');
   require_once($sourcedir .'/Subs-Post.php');


// CONFIGURATION SECTION

   $intro_form = "Put whatever introduction you want to appear at the top of the form here. You can add html. Be careful with quotation marks.";
   $thanks_text = "This is what will appear after the form is submitted. You can use html. Be careful with quotation marks.";

// Define your fields. All of these values need to be defined, even if they are empty.
// The fields will be displayed in the order in which they are listed in the array.
// $fielddef =
//   array(
//     array(
//       'caption' =>      "", // caption to be displayed on the form. Can include symbols and spaces.
//       'name' =>         "", // a unique name for the field. No symbols or spaces
//       'type' =>         "", // text, radio, select, checkbox, textarea, heading
//       'options' =>      "", // for radio and select fields. List in order you wish them to appear, separated by commas; for checkboxes, it's the value to be saved and displayed next to the box
//       'defaultvalue' => "", // the default value for the field. Can be a variable or text. Be sure to enclose text in quotation marks
//       'required' =>     0   // 0 or 1 -- use 1 if the field must be filled out. use 0 if it's optional; never set a checkbox to be required
//     ),
//   );

   $fielddef =
      array(
         array(
            'caption' =>      "Heading",
            'name' =>         "heading",
            'type' =>         "heading",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     0
         ),
         array(
            'caption' =>      "Name",
            'name' =>         "realname",
            'type' =>         "text",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1 
         ),
         array(
            'caption' =>      "Age",
            'name' =>         "age",
            'type' =>         "select",
            'options' =>      "13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40+",
            'defaultvalue' => "18",
            'required' =>     1
         ),     
         array(
            'caption' =>      "Sex",
            'name' =>         "sex",
            'type' =>         "radio",
            'options' =>      "M,F",
            'defaultvalue' => "",
            'required' =>     1
         ),     
         array(
            'caption' =>      "Do you like me?",
            'name' =>         "like",
            'type' =>         "checkbox",
            'options' =>      "Yes",
            'defaultvalue' => "Yes",
            'required' =>     0
         ),     
         array(
            'caption' =>      "Comments",
            'name' =>       "comments",
            'type' =>         "textarea",
            'options' =>      "",
            'defaultvalue' => "",
            'required' =>     1
         ),
      );



//send the application by email?
   $enable_email=false;

// email address of recruitment staff member
   $email_address='';

//post the application on forum?
   $enable_post=true;

//board id to which the application should be posted
   $board_id=2;

// Poll options
$add_poll = 1; // 0 = No poll; 1 = add poll
$poll_question = "Accept this member?"; // This is the question for the poll
$expireTime = 0; // Change this to the number of days you want the poll to run
$hideResults = 0; // 0 = Results are always visible; 1 = Can see results only after voting; 2 = Can see results only after poll expires
$changeVote = 0; // 0 = Voters can not change their votes; 1 = Voters can change their votes
$poll_choices = array('Yes','No'); // The options listed for the poll

//END OF CONFIGURATION SECTION
////////////////////////////////////////////////////////////////////////////////////////////


   $show_form= 'true';
   if (isset($_REQUEST['submitted'])) {  // Handle the form
// Check required fields
      $errors = array(); //Initialize error array   

      foreach ($fielddef as $field)
         if (empty($_REQUEST[$field['name']]) && ($field['required'] == 1)){ $errors[] = $field['name']; }
   
// There's at least one field missing
      if (isset($errors[0])) {
         foreach ($_REQUEST as $key => $value)
         $fieldvalue[$key] = $value;
      }
      else { // all is well
 
         $show_form='false';

         if ($enable_email)   {  // email an application
            $subject = 'Application';
            $body = '';
            foreach ($fielddef as $field) {
               if ($field['type'] == 'heading')
                  $body .= $field['caption'] . '
               ';
               else
                  $body .= $field['caption'] . ': ' . $_REQUEST[$field['name']] . '
               ';
            }
            mail($email_address, $subject, $body,"From: " . $user_info['email']);
         }

         if ($enable_post) {  //create new forum post with application
if ($add_poll === 1) {
$posterName = $context['user']['name'];
if ($expireTime > 0)
$expireTime = time() + $expireTime * 3600 * 24;
db_query("
INSERT INTO {$db_prefix}polls
(question, hideResults, maxVotes, expireTime, ID_MEMBER, posterName, changeVote)
VALUES ('$question', '$hideResults', '1', '$expireTime', '$ID_MEMBER', '$posterName', '$changeVote')", __FILE__, __LINE__);
$ID_POLL = db_insert_id();

// Create each answer choice.
$i = 0;
$setString = '';
foreach ($poll_choices as $option)
{
$setString .= "
('$ID_POLL', '$i', SUBSTRING('$option', 1, 255)),";
$i++;
}

db_query("
INSERT INTO {$db_prefix}poll_choices
(ID_POLL, ID_CHOICE, label)
VALUES" . substr($setString, 0, -1), __FILE__, __LINE__);

}
else
$ID_POLL = null;

            $postbody = 'Recruitment application has been made by ' . $context['user']['name'] .'<br /><br/>';
            foreach ($fielddef as $field) {
               if ($field['type'] == 'heading')
                  $postbody .= $field['caption'] . '<br />';
               else
                  $postbody .=  $field['caption'] . ': ' . $_REQUEST[$field['name']] . '<br />';
            }

            $msgOptions = array(
               'id' =>  0 ,
               'subject' => '[Pending] Application of ' . addslashes($_REQUEST['realname']),
               'body' => addslashes($postbody) ,
               'icon' => 'xx',
               'smileys_enabled' => true,
               'attachments' =>  array(),
            );
            $topicOptions = array(
               'id' => 0 ,
               'board' => $board_id,
               'poll' =>  $ID_POLL,
               'lock_mode' =>  null,
               'sticky_mode' =>  null,
               'mark_as_read' => true,
            );
            $posterOptions = array(
               'id' => $context['user']['id'],
               'name' => $context['user']['name'],
               'email' => $user_info['email'],
               'update_post_count' => true,
            );
            createPost($msgOptions, $topicOptions, $posterOptions);
         }
// Text for thank you page
         echo $thanks_text;
      }
   }
   else {
      foreach ($fielddef as $field) {
         $fieldvalue[$field['name']] = $field['defaultvalue'];
      }
   }

// Looks like you want the form,
   if ($show_form == 'true') {
      echo $intro_form . "<br>";
      if (isset($errors[0])) { echo '<div style="color: red;">Please fill in all fields with a *.</div>';  }

      echo '
   <form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
      <INPUT name="submitted" type="hidden" value="TRUE" />
        <table style="margin-left:auto; margin-right:auto;">';

      $bg = 'windowbg2';

      foreach ($fielddef as $field) {
// Headings have their own type of display
         if ($field['type'] == 'heading') {
            echo '
         <TR>
            <TD colspan="2" style="text-align: center; text-decoration: underline;">' .
               $field['caption'] . '
            </TD>
         </TR>';
         }

         else {

// How each field is displayed in the table
            echo '
         <TR class ="' . $bg . '">
            <TD align="right">';
              if ($field['required'] == 1) { echo '* '; }
              echo $field['caption'] . ':
            </TD>
            <TD align="left">';

// Go through each field type
            if ($field['type'] == 'text') {
               echo '<INPUT name="' . $field['name'] . '" type="text" value ="' . $fieldvalue[$field['name']] . '" />';
            }
            elseif ($field['type'] == 'radio') {
               $options = explode(',',$field['options']);
               foreach ($options as $option) {
                  echo '<INPUT TYPE="RADIO" NAME="' . $field['name'] . '" VALUE="'. $option . '"';
                  if ((isset($fieldvalue[$field['name']])) && ($option == $fieldvalue[$field['name']])) { echo ' CHECKED'; }
                  echo '>' . $option . ' ';
               }
            }
            elseif ($field['type'] == 'checkbox') {
               echo '<INPUT TYPE="CHECKBOX" NAME="' . $field['name'] . '" VALUE="'. $field['options'] . '"';
               if (isset($fieldvalue[$field['name']]) && ($fieldvalue[$field['name']]==$field['options'])) { echo ' CHECKED'; }
               echo '>' . $field['options']; 
            }
            elseif ($field['type'] == 'select') {
               echo '<SELECT name="' . $field['name'] . '" />';
               $options = explode(',',$field['options']);
               foreach ($options as $option) {
                  echo '<OPTION value="' . $option . '"';
                  if ((isset($fieldvalue[$field['name']])) && ($option == $fieldvalue[$field['name']])) { echo ' selected'; }
                  echo '>' . $option . '</OPTION>';
               }
               echo '</SELECT>';
            }   
            elseif ($field['type'] == 'textarea') {
               echo '<TEXTAREA name="' . $field['name'] . '" rows="4" cols="40">';
               echo $fieldvalue[$field['name']];
               echo '</' . 'TEXTAREA>';
            }

// Finish off the row
            echo '
            </TD>
         </TR>';
         }

// Set up the alternating colors for the next row
         ($bg == 'windowbg2') ? $bg = 'windowbg' : $bg = 'windowbg2';
      }

      echo '
         <TR class ="' . $bg . '">
            <TD colspan="2" align="center">
               <INPUT type="submit" value="Submit">
               <INPUT type="reset" value="Reset">
            </TD>
         </TR>
      </TABLE>
   </form>';
   }
}


Offline EzPortal

  • Administrator
  • *****
  • Posts: 1298
  • Karma: 67
Re: sign up form for ezBlocks
« Reply #1 on: February 27, 2012, 06:12:19 pm »
Thanks for the post! Looks good notes for all it is for SMF 1.1.x
Like ezPortal? Support me at https://www.patreon.com/vbgamer45/

 

Related Topics

  Subject / Started by Replies Last post
sign up

Started by dude Support

5 Replies
8787 Views
Last post May 07, 2009, 11:28:10 pm
by dude
EzBlocks?

Started by Eddy Matthews « 1 2 » Support

15 Replies
20123 Views
Last post October 29, 2009, 05:59:37 pm
by EzPortal
2 Replies
8522 Views
Last post January 16, 2010, 10:45:21 am
by amorosso
3 Replies
9847 Views
Last post June 23, 2011, 12:27:35 am
by kd61
2 Replies
11889 Views
Last post March 02, 2011, 02:17:06 pm
by darwiin

+-SMF Gallery

Quick Menu


Powered by EzPortal