TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,911
  • Total Topics: 21,307
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 362
  • Total: 363
  • tino

[Done!] Join Us! form

Started by mebymyself, October 19, 2006, 08:10:13 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Inny

Check:
$board_id=15.0;

im not a php expert but the .0 shouldn't be there.

Also try it without:

if ($context['user']['is_guest'])
{
   echo
   '<h5>Access Denied</h5>
   We are sorry. You must be registred on the site in order to apply for Wisdom and Strength.';
} else  { // remove closing bracket


and since you have database connection issues i think the problem lies somewhere in here:

// CONFIGURATION SECTION

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

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

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

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

//the id of the this article
$this_article_id = '14';

//article to be redirected when form is submitted
$thank_you_article_id = '13';


//END OF CONFIGURATION SECTION


JPDeni

In looking over it again, I'm wondering if there might be a problem with your "thank you" page. What's on it?

durgia

Hi!

I looked through the thread and did not see that one option I would like had been designed by anybody yet. If I missed it, I apologize.

I am looking to add in a bit of code so that the form is not only sent to me but a copy is also sent to the person filling out the form, as confirmation that they have registered. I am using a version of the form I found in this thread to allow people to Register for an upcoming event.

I have attached a copy of the code I am using. One of the mandatory fields I have specified is an email address so I thought I could use that info added to the part that already emails me, but I have not had any luck so far.

Please Note: out of necessity I am allowing Guests to use this form and therefor cannot pull the email address out of the user info command.

As an alternative I wondered if I could make the completed form show up on the Thank you page and then they could print it as a type of receipt.

global $sourcedir, $user_info, $context ;

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



// CONFIGURATION SECTION

$intro_form = "Please use this online registration form to enroll in the Professional Development Day: Generational Differences.";   // Can include html

$thanks_text = "Thank you for registering. "; // what is displayed after the form is submitted

// 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' =>      " First Name",
      'name' =>         "fname",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1   
    ),
    array(
      'caption' =>      " Last Name",
      'name' =>         "lname",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1   
    ),
    array(
      'caption' =>      "Email Address",
      'name' =>         "email",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
    ),
    array(
      'caption' =>      "Mailing Address",
      'name' =>         "address",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1   
),
    array(
      'caption' =>      "City",
      'name' =>         "city",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
),
    array(
      'caption' =>      "Province",
      'name' =>         "province",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
),
    array(
      'caption' =>      "Postal Code",
      'name' =>         "postal",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     1
),
    array(
      'caption' =>      "Preferred Date",
      'name' =>         "date",
      'type' =>         "select",
      'options' =>      "May 12,May 13",
      'defaultvalue' => "",
      'required' =>     1
    ),
array(
      'caption' =>      "",
      'name' =>         "member",
      'type' =>         "radio",
      'options' =>      "Member ($250),Non-Member ($300)",
      'defaultvalue' => "",
      'required' =>     1
    ), 
    array(
      'caption' =>      "Company",
      'name' =>         "company",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     0
    ),
    array(
      'caption' =>      "Contact Phone Number (optional)",
      'name' =>         "phone",
      'type' =>         "text",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     0
    ),
    array(
      'caption' =>      "Additional Information (optional)",
      'name' =>         "info",
      'type' =>         "textarea",
      'options' =>      "",
      'defaultvalue' => "",
      'required' =>     0
    ),
);


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

// email address of staff member
$email_address='testing@testing.org';

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

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


//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 = 'Enrollment: Testing';
  $body = 'Testing only: Registration has been made by ' . $context['user']['name'] .
          ' from IP Address ' . $user_info['ip'] . '
              ';
      foreach ($fielddef as $field) {
        $body .= $field['caption'] . ': ' . $_REQUEST[$field['name']] . '
        ';
      }
      mail($email_address, $subject, $body,"From: " . $user_info['email']);
    }

    if ($enable_post) {  //create new forum post with application

      $postbody = 'Enrollment application has been made by ' . $context['user']['name'] .'<br />
                   <table>';
      foreach ($fielddef as $field) {
        $postbody .= '<tr><td>' . $field['caption'] . '<td></td><td>  ' . $_REQUEST[$field['name']] . '</td></tr>';
      }
      $postbody .= '</table>';

      $msgOptions = array(
        'id' =>  0 ,
        'subject' => '[Pending] Application of ' . $context['user']['name'],
        'body' => $postbody ,
        'icon' => 'xx',
        'smileys_enabled' => true,
        'attachments' =>  array(),
      );
      $topicOptions = array(
        'id' => 0 ,
        'board' => $board_id,
        'poll' =>  null,
        '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;
  }
}

// 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="' . $scripturl . '?page='  . $_GET['page'] . '" method="post">
        <INPUT id="submitted" name="submitted" type="hidden" value="TRUE" />
        <center><table width="100%">';
  $bg = 'windowbg2';
  foreach ($fielddef as $field) {
    if ($field['type'] == 'text') {
      echo '<TR class ="' . $bg . '">
              <TD width = "200px" align="right">';
              if ($field['required'] == 1) { echo '<div style="color: red;">*</div> '; }
              echo $field['caption'] . ':</TD>
              <TD align="left"><INPUT id="' . $field['name'] . '" name="' . $field['name'] . '" type="text" value ="' . $fieldvalue[$field['name']] . '" /></TD>
            </TR>';
    }
    elseif ($field['type'] == 'radio') {
      echo '<TR class ="' . $bg . '">
              <TD width = "200px" align="right">';
              if ($field['required'] == 1) { echo '<div style="color: red;">*</div> '; }
              echo $field['caption'] . ':</TD>
              <TD align="left">';
              $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 . ' ';
              }
              echo '</TD>
            </TR>';   
    }
    elseif ($field['type'] == 'checkbox') {
      echo '<TR class ="' . $bg . '">
              <TD width = "200px" align="right">';
              echo $field['caption'] . ':</TD>
              <TD align="left">';
                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'] . '
            </TR>';   
    }
    elseif ($field['type'] == 'select') {
      echo '<TR class ="' . $bg . '">
              <TD width = "200px" align="right">';
              if ($field['required'] == 1) { echo '<div style="color: red;">*</div> '; }
              echo $field['caption'] . ':</TD>
              <TD align="left"><SELECT id="' . $field['name'] . '" name="' . $field['name'] . '" style="WIDTH: 152px" value ="';
              echo '" />';
              $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></TD>
            </TR>';
    }
    elseif ($field['type'] == 'textarea') {
      echo '<TR class ="' . $bg . '">
            <TD width = "200px" align="right">';
            if ($field['required'] == 1) { echo '<div style="color: red;">*</div> '; }
            echo $field['caption'] . ':</TD>
            <TD align="left"><TEXTAREA id="' . $field['name'] . '" name="' . $field['name'] . '" rows="4" cols="40">';
            echo $fieldvalue[$field['name']];
            echo '</' . 'TEXTAREA></TD>
  </TR>';
    }
    elseif ($field['type'] == 'heading') {
      echo '<TR class ="' . $bg . '">
            <TD colspan="2">' .
            $field['caption'] .
            '</TD></TR>';
    }
    if ($bg == 'windowbg2') { $bg = 'windowbg'; }
    else { $bg = 'windowbg2'; }
  }
  echo '
    <TR class ="' . $bg . '">
      <TD colspan="2" align="center">
        <INPUT type="submit" value="Submit">
        <INPUT type="reset" value="Reset"></TD>
    </TR></TABLE></center></form>';
}

JPDeni

#293
This is getting confusing. I'll start putting the person's name in that I'm responding to. I've got one person using one bit of code and having errors and another person using another bit of code who wants more features.

durgia

Looks like, to mail the same thing to the user that you mail to the admin, after


mail($email_address, $subject, $body,"From: " . $user_info['email']);

(BTW, this should be changed to

mail($email_address, $subject, $body,"From: " . $_REQUEST['email']);

because you are allowing guests.)

add


mail($_REQUEST['email'], $subject, $body,"From: " . $email_address);


To add the info to the "thank you" page, change


echo $thanks_text;


to


echo $thanks_text;
echo '<table>';
foreach ($fielddef as $field)
        echo '<tr><td>' . $field['caption'] . '</td><td>  ' . $_REQUEST[$field['name']] . '</td></tr>';
echo '</table>';

durgia

you are the best, as always!!

btw (for anybody else using this in the future) there is a small syntax error in the code provided

echo $thanks_text;
echo '<table>';
foreach ($fielddef as $field) {
        echo '<tr><td>' . $field['caption'] . '</td><td>  ' . $_REQUEST[$field['name']] . '</td></tr>';
echo '</table>';


is missing a bracket and should be

echo $thanks_text;
echo '<table>';
foreach ($fielddef as $field) {
        echo '<tr><td>' . $field['caption'] . '</td><td>  ' . $_REQUEST[$field['name']] . '</td></tr>'; }
echo '</table>';

JPDeni

Sorry 'bout that. :) I actually intended for there not to be an opening bracket. I must have forgotten to delete it.

Glad you figured it out, though, and that it works for you.

durgia

No need to apologize for helping me, One of these days I will learn enough to do things on my own :)

I actually tried it without the bracket but it made a very strange output that was scattered around, so I think the bracket is needed. At least it works much better with it :)

Thanks again!


darrenelkins

Quote from: JPDeni on February 10, 2009, 03:35:30 PM
In looking over it again, I'm wondering if there might be a problem with your "thank you" page. What's on it?

Here is what is on my Thank You article, I dont think I have any database issues as all else works fine. Thanks


global $user_info;
echo "
<h3>Thank you for applying, " . $user_info['name'] . "! </h3><br />
<p>Your application has been sent to our recruitment officers by email and also new topic has been created on your behave in  Recruitment Department's forum. <br/>
Our decision will be posted here. You also will receive an email when the decision will be done.<br/>
Please feel free to add any information you want to share with us.<br/>
<br /></p>";


JPDeni

Shaktii, I just don't know what the problem is. The code uses a function within SMF to write to the database and you say that the post is being added, so the function is being run. I've never seen any problem like that before.

darrenelkins

Quote from: JPDeni on February 11, 2009, 12:06:22 AM
Shaktii, I just don't know what the problem is. The code uses a function within SMF to write to the database and you say that the post is being added, so the function is being run. I've never seen any problem like that before.

:( ok, I will simply have to try and find the other recruitment block code that worked for me, it's just that I preferred this look to the other I had, damn, I wish I kept the code now :(

Thanks for your time.

This website is proudly hosted on Crocweb Cloud Website Hosting.