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,913
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 460
  • Total: 460

Article - New topic form (pre-formated topic)

Started by londonhogfan, April 20, 2006, 05:14:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DrakeBrimstone

#30
Here is what I have so far, includes required field validation


<?php


class ftfFormField{
public 
$DisplayText;
public 
$Type;
public 
$DefaultValue;
public 
$PostText;
public 
$Required;
public 
$SizeW;
public 
$SizeH;


public function 
__construct($DisplayText$Type$DefaultValue$PostText$SizeW$SizeH$Required=0){
$this->DisplayText $DisplayText;
$this->Type $Type;
$this->DefaultValue $DefaultValue;
$this->PostText $PostText;
$this->SizeW $SizeW;
$this->SizeH $SizeH;
$this->Required $Required;


}

public function 
DisplayField($id){


if(
$this->Type==1){

echo 
"<tr><td>\n";
if(
$this->Required)
{
echo 
"*";
}
echo 
$this->DisplayText;
echo 
"</td><td>\n";
echo 
"<input name='f";
echo 
$id;
echo 
"' pText='";
echo 
$this->PostText;
echo 
"' bReq=";
echo 
$this->Required;
echo 
" type='text' value='";
echo 
$this->DefaultValue;
echo 
"' size='";
echo (string) 
$this->SizeW;
echo 
"'>\n";

}
elseif(
$this->Type==2){

echo 
"<tr><td colspan=2>\n";
if(
$this->Required)
{
echo 
"*";
}
echo 
$this->DisplayText;
echo 
"</td>";
echo 
"</tr><tr><td colspan=2>\n";
echo 
"<textarea name='f";
echo 
$id;
echo 
"' pText='";
echo 
$this->PostText;
echo 
"' bReq=";
echo 
$this->Required;
echo 
" cols='";
echo (string) 
$this->SizeW;
echo 
"' rows='";
echo (string) 
$this->SizeH;
echo 
"'>";
echo 
$this->DefaultValue;
echo 
"</textarea>\n";
}
elseif(
$this->Type==3){

echo 
"<tr><td colspan=2>\n";
if(
$this->Required)
{
echo 
"*";
}
echo 
$this->DisplayText;
echo 
"\n<input name='f";
echo 
$id;
echo 
"' pText='";
echo 
$this->PostText;
echo 
"' bReq=";
echo 
$this->Required;
echo 
" type='radio' value='Yes'";

if(
$this->DefaultValue=="Yes"){
echo 
" checked";
}

echo 
">Yes <input name='f";
echo 
$id;
echo 
"' type='radio' value='No'";

if(
$this->DefaultValue=="No"){
echo 
" checked";
}

echo 
">No\n";
}
echo 
"</td></tr>\n";

}


}





$ftfFieldArray = array();

//Copy and paste the line below (uncomment it) and fill it out for each field you wish to have.
//You must enter numbers starting with 0 in the [] sequentualy as you wish it to appear on the page. Do not skip numbers.
//The first value in the is for the displayed text on the form
//The second value, a number, is the vield type (1=text, 2=textarea, 3= Yes/No)
//The third value is the default value, text for types 1&2 and "Yes" or "No" for type 3
//The fourth value is the text you wish to display in the post.
//The fith value is the width of the textbox or textarea in pixlies. Leave 0 for type 3.
//The sixth value is the hight of a textarea in rows. Leave 0 for types 1 and 3.
//The seventh, and last, states if the field is required (1 for required, 0 for not required)

//--------------------------------------------------
//$ftfFieldArray[] = new ftfFormField("",1,"","",0,0,1);
//--------------------------------------------------

//--------------------------------------------------
//This is the ONLY area you edit, insert the field informaton below
//--------------------------------------------------



//--------------------------------------------------
//End Field Information
//--------------------------------------------------

//--------------------------------------------------
//enter the array number for the field that is to be used for the subject
//--------------------------------------------------
$ftfSubjectField 4;
//--------------------------------------------------

//--------------------------------------------------
//enter the correct url and board id below. Example provided.
//--------------------------------------------------
$ftfURL "http://www.domain.com/forums/index.php?action=post;board=29.0";
//--------------------------------------------------

//--------------------------------------------------
//This ends the field definition area, do not modify below this point
//--------------------------------------------------




//--------------------------------------------------

echo "<form name='frmFill'>";
echo 
"<div align='center'>";
echo 
"<table>";
$ftfid=0;
foreach (
$ftfFieldArray as $ftfField)
{
$ftfField->DisplayField($ftfid);
$ftfid=$ftfid+1;
}


echo 
"</table>";
echo 
"</div>";
echo 
"</form>";

?>


<!--form action='<?php echo $ftfURL?>' method='post' name='postmodify' target='_parent' id='postmodify' style='margin: 0;'-->
<form name='postmodify'>
<input type='hidden' name='subject'>
<input name='icon' id='icon' value='xx' type='hidden'>
<input type='hidden' name='message'>
<input type='hidden' name='sc' value='', $context['session_id'], '' />

<div align='center'>
<input type='button' name='btnSubmit' value='Apply' onclick='CompileForm()'>
</div>

</form>



<script>


function CompileForm()
{

if (!(CheckRequired())) return;

strCompiled="";

<?php
echo "\n\n\n\n";
echo 
"document.postmodify.subject.value=document.frmFill.f";
echo 
$ftfSubjectField;
echo 
".value;\n";

$ftfid=0;
foreach (
$ftfFieldArray as $ftfField)
{
echo 
"strCompiled=strCompiled+document.frmFill.f";
echo 
$ftfid;

if (
$ftfField->Type==3)
{
echo 
"[0]";
}

echo 
".pText+";
if (
$ftfField->Type==2)
{
echo 
"'\\n'+";
}
echo 
"document.frmFill.f";

echo 
$ftfid;

if (
$ftfField->Type==3)
{
echo 
"[0]";
}

echo 
".value+'\\n';\n";

$ftfid=$ftfid+1;
}
?>




document.postmodify.message.value=strCompiled;

alert(document.postmodify.subject.value+'\n\n'+document.postmodify.message.value);
//alert('test');
//document.postmodify.submit();


}



function CheckRequired()
{
<?php
$ftfid
=0;
$ftffid=0;
foreach (
$ftfFieldArray as $ftfField)
{
if (
$ftfField->Required)
{
if (
$ftfField->Type==1)
{
echo 
"if (document.frmFill.f";
echo 
$ftfid;
echo 
".value=='')\n{\nalert('Please Fill out All Required Fields1');\ndocument.frmFill.elements[";
echo 
$ftffid;
echo 
"].focus();\nreturn 0;\n}\n";
}
elseif (
$ftfField->Type==2)
{
echo 
"if (document.frmFill.f";
echo 
$ftfid;
echo 
".value=='')\n{\nalert('Please Fill out All Required Fields2');\ndocument.frmFill.elements[";
echo 
$ftffid;
echo 
"].focus();\nreturn 0;\n}\n";
}
elseif (
$ftfField->Type==3)
{
echo 
"if (!(document.frmFill.f";
echo 
$ftfid;
echo 
"[0].checked))\n{\n";
echo 
"if (!(document.frmFill.f";
echo 
$ftfid;
echo 
"[1].checked))\n{\n";
echo 
"\nalert('Please Fill out All Required Fields3');\ndocument.frmFill.elements[";
echo 
$ftffid;
echo 
"].focus();\nreturn 0;\n}\n}\n";
}
}

if (
$ftfField->Type==3)
{
$ftffid=$ftffid+1;
}

$ftffid=$ftffid+1;
$ftfid=$ftfid+1;

}


?>


return true;
}




</script>





An example that displays the results in an alert box can be found at the following url

*edit* fully modified now for variable compatability, took me less time thing I thought.

http://www.drakebrimstone.com/testform/testphpform.php


londonhogfan

this is great!

I started this topic about 3 weeks ago and the TP community did an awesome job working it out.

Thanks everyone.

now if someone could make a roster page :D

examino

Quote from: MyFSI on April 28, 2006, 08:33:49 PM
Write this in a PHP article:


echo'
<div align="center">
<form action="http://www.the-rota.com/index.php?action=post2;board=5" method="post" name="postmodify" id="postmodify" style="margin: 0;">
Your Gaming Alias - dd/mm/yyyy<br>
<input type="text" name="subject" tabindex="1" size="80" maxlength="80" />
<br><br>
<input name="icon" id="icon" value="xx" type="hidden">
<textarea class="editor" name="message" rows="25" cols="60" tabindex="2">

In Game Alias:

First Name:

Email Address:

XFire Name:

Location(State or Country):

Age:

Invited By: (If any)

Leagues Played In: (If any)

Have you ever been an admin in another clan?:

Why do you want to join ~RoTa~?:

Have you read and understand the Code of Conduct?:

Do you understand our member/recruit process and requirements?:

Are you willing to uphold these at ALL times?:

Any other comments or suggestions?:

</textarea><br>

<input type="submit" name="post" value="Submit" tabindex="3">
<input type="hidden" name="sc" value="', $context['session_id'], '" />
</form>
</div>';


notice the added line:
<input type="hidden" name="sc" value="', $context['session_id'], '" />
this will include your session id so it won't give you that error again.

Is there anyway to use this script or a modified version of it in order to get users inpun in my EMAIL? Also I want to display as an article perhaps, a thank you page... Is this possible...somehow?

technodragon73

for email you would just use a normal form. the purpose of this was to make it so you did not have to use the traditional email method.

examino


technodragon73

just do a search on the internet for creating html forms...there are loads of tutotrials as well as automated form generators available.  Even most html programs will guide you through creating a form...

samson

could someone please take a quick look and let me know what I am doing wrong. I am trying to use the last post from DrakeBrimstone

//You must enter numbers starting with 0 in the [] sequentualy as you wish it to appear on the page. Do not skip numbers.
// 1 The first value in the is for the displayed text on the form
// 2 The second value, a number, is the vield type (1=text, 2=textarea, 3= Yes/No)
// 3 The third value is the default value, text for types 1&2 and "Yes" or "No" for type 3
// 4 The fourth value is the text you wish to display in the post.
// 5 The fith value is the width of the textbox or textarea in pixlies. Leave 0 for type 3.
// 6 The sixth value is the hight of a textarea in rows. Leave 0 for types 1 and 3.
// 7 The seventh, and last, states if the field is required (1 for required, 0 for not required)

//--------------------------------------------------
//$ftfFieldArray[] = new ftfFormField("",1,"","",0,0,1);
//--------------------------------------------------

//--------------------------------------------------
//This is the ONLY area you edit, insert the field informaton below
//--------------------------------------------------

$ftfFieldArray[0] = new ftfFormField("Real first name:",1,"text","Real first name:",20,1,1);

//--------------------------------------------------
//End Field Information


everytime I hit submit I get an error window

you can give it a try here
http://www.ligs.us/smf3/index.php?page=52

Im sure im doing somthing wrong any help would be appreiciated

Flex

So, Can someone please post the whole code, not just bits and pieces?. I'd like to use this but I have no idea of what I'm doing. Thanks.

animecosmo

When I use the original code posted, no changes what so ever (other than to make it post in my own forum), it works just fine. However, if I change the fields in it to read:

Quote
BASICS
Character Name:
Gender:
Birthdate:
Ancestry:

* Ancestry type can be pureblood (both parents are wizards), Muggle-born (neither parent is a wizard; you must choose this type for your first character if you do not know much about the Harry Potter books), or half-blood (one wizard parent, one non-wizard parent).

FAMILY
Names of parents/guardians (MUST have at least one adult parent/guardian):

Names of siblings (optional):

Description (physical and personality) of parents/guardians:

Description (physical and personality) of siblings (optional):

Other (anything else noteworthy about the family):

PHYSICAL ATTRIBUTES
Hair Colour:
Hair Style/Type:
Skin Tone:
Eye Colour:
Height (Short, tall, average, a bit tall, etc.):
Build (Thin, athletic, fat, etc.):
Other (Anything else you want to describe, optional):

PERSONALITY
Describe your character's personality in as much detail as you can.

OTHER ATTRIBUTES
Likes:
Dislike:
Fears:
Hobbies/Interests:
Goals/Dream Job (if known yet):
Best Subject:
Worst Subject:
Other (anything else noteworthy, optional):

Pet (Owl, cat, rat, toad, fox, small snake, raven):

* For the subjects, if it is a first year student, put what they are going to be best in (since they haven't started school yet).

ABILITIES
For these abilities, choose very poor, poor, average, above average, or excellent. You have 15 total points to spend in these areas. See the chart below for adding or subracting points from your total.

Dismal: +3 points
Very Poor: +2 points
Poor: +1 point
Average: 0 points
Good: -1 point
Very Good: -2 points
Exceptional: -3 points

Memorization Ability (Ability to read/hear/see something and remember it):
Cunning (How tricky and manipulative are you?):
Problem Solving:
Concentration (Can you avoid being distracted?):
Creativity:

Bravery:
Self-Confidence:
Magical Ability (How powerful a wizard/witch):
Future Seeing Ability:

Speed (How fast are you, athletically?):
Agility (Can you dodge and move easily?):
Strength (How strong are you?):
Accuracy/Aim (Applies to spells and physical objects):

Charm (Can you talk your way into/out of things?):
Popularity (How well are you liked):
Fame (How famous are you?):
Tact (Can you say things without offending others?):
Looks:

Sneaking (How good are you at hiding, sneaking, etc.?):
Practical Joking:
Mischief (Are you good at getting away with mischief?):

It gives me an error:

Parse error: syntax error, unexpected '<' in /home/(name edited out)/public_html/Forum/Sources/Load.php(1768) : eval()'d code(231) : eval()'d code on line 1

Every other version of the code posted gives an error as well. I tried taking out the things with an astrisk, too. Any ideas?

Noam

Late to the party, I know, but in case people were looking for some other examples, here's one for our WoW guild. We needed some longer text entry areas, and believe me, getting textareas on the form was a pain:

Made a php article titled "Apply to FOO" and linked it off the front page, contents follows:


/*
Noam's Notes:
0. Backslash every apostrophe in the big echo statement below.
1. Never, ever put in a closing textarea tag literally. It will screw up the article editor somethin' fierce. Use '</text'.'area>' instead.
*/
echo '
<form name="application">
    <p>1. Say hello and tell us a little bit about yourself: this is the only in-character question in this application. If you\'re new to RP don\'t stress over this. Just a quick hello and who you are.<br />
    Character Name: <input type="text" name="characterName" size="40"><br>
    Character Introduction:<br>
    <textarea rows="10" cols="80" name="characterIntro"></text'.'area></p>
    <p>2. Is this your main character and what level are you?<br />
    <input type="radio" name="isMain" value="Yes" />Yes, this is my main character.<br />
    <input type="radio" checked="checked" name="isMain" value="No" />No, this is not my main character.<br />
    <input maxlength="2" size="3" name="characterLevel" type="text" />Level</p>
    <p>3. Please list the guilds on BAR you have been a member of. If you\'re a transfer, please list the server and guilds you have transferred from and the reason you transferred.<br />
    <textarea rows="10" cols="80" name="priorGuilds"></text'.'area></p>
    <p>4. Do you have any Alternative Characters you wish to bring into the guild? If yes, what are their names and levels?<br />
    <textarea rows="10" cols="80" name="altCharacters"></text'.'area></p>
    <p>5. Have you ever had a character enrolled in FOO or BAZ in the past? If yes, what were your reasons for leaving, and what was the name of the character you were enrolled under?<br />
    <textarea rows="10" cols="80" name="priorFooCharacters"></text'.'area></p>
    <p>6. What is it that you are looking for in and want from a guild?<br />
    <textarea rows="10" cols="80" name="whatLookingFor"></text'.'area></p>
    <p>7. What is it you bring to the guild? (trade skills, etc. Anything else you think is pertinent)<br />
    <textarea rows="10" cols="80" name="whatBringing"></text'.'area></p>
    <p>8. What is your RP (Role Playing) experience?<br />
    <textarea rows="10" cols="80" name="rpExperience"></text'.'area></p>
    <p>9. How long have you played WoW?<br />
    <textarea rows="10" cols="80" name="howLongPlayed"></text'.'area></p>
    <p>10. Have you created a history or back story for you character? (not a requirement; see the Conduct)<br />
    <input type="radio" name="hasBackstory" value="Yes" />Yes, I have a backstory.<br />
    <input type="radio" checked="checked" name="hasBackstory" value="No" />No, I have no backstory.</p>
    <p>Do you understand this must comply with WoW\'s Azerothian Lore as well as FOO\'s Lore and Conduct?<br />
    <input type="radio" name="understandLore" value="Yes" />Yes, I understand.<br />
    <input type="radio" checked="checked" name="understandLore" value="No" />No, I don\'t understand.</p>
    <p>How do you feel about advice or comments on your character\'s history/backstory?<br />
    <textarea rows="10" cols="80" name="feelAboutComments"></text'.'area></p>
    <p>11. Have you read The Conduct of FOO and agree to abide by these guidelines and rules?<br />
    <input type="radio" name="hasReadConduct" value="Yes" />Yes, I\'ve read it and I agree.<br />
    <input type="radio" checked="checked" name="hasReadConduct" value="No" />No. I\'ve either not read it, or don\'t agree.</p>
    <p>12. Do you have any comments or questions regarding joining or being a member of FOO?<br />
    <textarea rows="10" cols="80" name="commentsAndQuestions"></text'.'area></p>
    <p>13. Where did you hear of FOO?<br />
    <textarea rows="10" cols="80" name="whereYouHeard"></text'.'area></p>
</form>
<p>Thank you for your time in filling this out and reading the Conduct. We look forward to meeting you in game.</p>

<form action="http://SERVERNAME/index.php?action=post;board=TARGETBOARD" method="post" name="postmodify" id="postmodify" style="margin: 0;">
<input type="hidden" name="subject">
<input type="hidden" name="icon" id="icon" value="xx">
<input type="hidden" name="message">
<input type="hidden" name="sc" value="'.$context['session_id'].'">

<script>
function CompileForm()
{

  characterName=document.application.characterName.value;
  characterIntro=document.application.characterIntro.value;

  for (i=0;i<document.application.isMain.length;i++){
    if (document.application.isMain[i].checked==true){
      theone=i; break;
    }
  }
  if (theone==0) { isMain="Yes"; } else { isMain="No"; }

  characterLevel=document.application.characterLevel.value;
  priorGuilds=document.application.priorGuilds.value;
  altCharacters=document.application.altCharacters.value;
  priorFooCharacters=document.application.priorFooCharacters.value;
  whatLookingFor=document.application.whatLookingFor.value;
  whatBringing=document.application.whatBringing.value;
  rpExperience=document.application.rpExperience.value;
  howLongPlayed=document.application.howLongPlayed.value;

  for (i=0;i<document.application.hasBackstory.length;i++){
    if (document.application.hasBackstory[i].checked==true){
      theone=i; break;
    }
  }
  if (theone==0) { hasBackstory="Yes"; } else { hasBackstory="No"; }

  for (i=0;i<document.application.understandLore.length;i++){
    if (document.application.understandLore[i].checked==true){
      theone=i; break;
    }
  }
  if (theone==0) { understandLore="Yes"; } else { understandLore="No"; }

  feelAboutComments=document.application.feelAboutComments.value;

  for (i=0;i<document.application.hasReadConduct.length;i++){
    if (document.application.hasReadConduct[i].checked==true){
      theone=i; break;
    }
  }
  if (theone==0) { hasReadConduct="Yes"; } else { hasReadConduct="No"; }

  commentsAndQuestions=document.application.commentsAndQuestions.value;
  whereYouHeard=document.application.whereYouHeard.value;

  strCompiled=
    "[b]Character name:[/b] " + characterName + "\n\n" +
    "[b]Character introduction:[/b]\n" + characterIntro + "\n\n" +
    "[b]Main character?[/b] " + isMain + "\n" +
    "Level " + characterLevel + "\n\n" +
    "[b]Prior guilds:[/b]\n" + priorGuilds + "\n\n" +
    "[b]Alt characters:[/b]\n" + altCharacters + "\n\n" +
    "[b]Prior FOO characters:[/b]\n" + priorFooCharacters + "\n\n" +
    "[b]What you\'re looking for:[/b]\n" + whatLookingFor + "\n\n" +
    "[b]What you\'re bringing:[/b]\n"  + whatBringing + "\n\n" +
    "[b]RP experience:[/b]\n" + rpExperience + "\n\n" +
    "[b]How long you\'ve played WoW:[/b]\n" + howLongPlayed + "\n\n" +
    "[b]Has a backstory:[/b] " + hasBackstory + "\n" +
    "[b]Understands compliance with Lore:[/b] " + understandLore + "\n\n" +
    "[b]Feels about comments on backstory:[/b] " + feelAboutComments + "\n\n" +
    "[b]Has read conduct and agrees:[/b] " + hasReadConduct + "\n" +
    "[b]Comments/questions:[/b]\n" + commentsAndQuestions + "\n\n" +
    "[b]Where you heard about FOO:[/b]\n" + whereYouHeard;
 
  document.postmodify.subject.value="New Member Application: "+characterName;
  document.postmodify.message.value=strCompiled;
 
  document.postmodify.submit();
}
</script>

Click the button below, and you\'ll see a pre-formatted post on the member applications board, where you will still need to hit the Post button to actually apply.<br>
<input type="button" name="btnSubmit" value="Submit Application" onclick="CompileForm()">
</form>
';


This website is proudly hosted on Crocweb Cloud Website Hosting.