/    Sign up×
Community /Pin to ProfileBookmark

Action script help needed

I looked through the threads and can’t find what I need.

What I want to do is create a user input form that will fill a new form on a page when filled out and submitted.

Basically, it will be an “add field” form that will read out like a story in the new text box that can be copied to post in a forum.

Does this make sense?

For example

Username (input text) (user inputs “Bill)
Occupation (input text)(user inputs “Architect”)
Age (input text)(user inputs “27”)

And then when submitted, there would be an output that would read

[I]Bill, who is a 27 year old Architect……..[/I]

Of course once I know the basic “POST” code to get it to post to the same webpage, I can figure out the input fields and how to expand it to my needs.

Thank you to any who responds.

to post a comment
PHP

14 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisDec 23.2006 — Not sure I understand everything you're asking. However, to do the form thing with a POST requires server-side code. To give you an idea, though, the following GET method, using a JavaScript demonstration, does at least part of what I think you're asking for:
[code=html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Submit to Self</title>
<script type="text/javascript">
<!--//
function ValidateForm(f)
{
if(ValueMissing(f.elements['First Name'])) return false;
if(ValueMissing(f.elements['Occupation'])) return false;
if(ValueMissing(f.elements['Current Age'])) return false;
return true;
}
function ValueMissing(f)
{
if(f.value.isEmpty())
{
alert(f.name + ' is a required field. Please try again.');
if(f.select) f.select();
if(f.focus) f.focus();
return true;
}
return false;
}
//
String.prototype.isEmpty = function () { return /^s*$/.test(this.toString()); }
String.prototype.trimEnds = function () { return this.replace(/(^s+)|(s+$)/g, ''); }
String.prototype.parsePairs = function () // parse delimited string of name/value pairs
{
if (this.length == 0) return null; // return null for zero-length string
var p_delim = (arguments[0]) ? arguments[0] : '&'; // set default pair delimiter
var n_delim = (arguments[1]) ? arguments[1] : '='; // set default name delimiter
var items = this.split(p_delim); // split argument string into an array
var x, len = items.length; // get number of name/value pairs
for (x=0; x<len; ++x) // loop on name/value pairs
{
items[x] = items[x].split(n_delim); // split them and re-add to array
items[x][0] = unescape(items[x][0].replace(/+/g,' ')).trimEnds(); // massage and trim name value
items[x][1] = (items[x][1]) ? unescape(items[x][1].replace(/+/g,' ')).trimEnds() : ""; // massage and trim data value
if (items[x][0].length > 0) { // add hash entry, also
if (typeof items[items[x][0]] == 'undefined') {
items[items[x][0]] = items[x][1];
} else { // use array for duplicate hash entries
if (typeof items[items[x][0]] != 'object') {
items[items[x][0]] = new Array(items[items[x][0]]);
}
items[items[x][0]].push(items[x][1]);
}
}
} // end loop
return items;
}
//-->
</script>
</head>

<body>
<form action="" method="get" onsubmit="return ValidateForm(this)">
<p>First name: <input type="text" name="First Name" size="20"><br>
Occupation: <input type="text" name="Occupation" size="20"><br>
Current age: <input type="text" name="Current Age" size="20"></p>
<p><input type="submit" value="Submit" alt="Submit"></p>
</form>
<p>&nbsp;</p>
<script type="text/javascript">
<!--//
var str = self.location.search.substr(1);
if (str.length > 0)
{
var _get = str.parsePairs();
str = '<p>';
str += _get['First Name'];
str += ', who is a ';
str += _get['Current Age'];
str += '-year-old ';
str += _get['Occupation'];
str += ', ...</p>';
document.writeln(str);
}
//-->
</script>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@so_is_thisDec 23.2006 — Sorry, I thought I was in the JavaScript forum. Here is the PHP version of that (using POST):
[code=php]
<?php
function is_empty($str)
{
return (1 == preg_match('/^s*$/', $str));
}
$messages = '';
$output = '';
$first_name = '';
$occupation = '';
$current_age = '';
if($_SERVER['REQUEST_METHOD'] == 'POST'):
if(!isset($_POST['First_Name'])
|| is_empty($_POST['First_Name']) ):
$messages .= 'First Name is a required field. Please try again.' . "<br>n";
else:
$first_name = htmlentities($_POST['First_Name']);
endif;
if(!isset($_POST['Occupation'])
|| is_empty($_POST['Occupation']) ):
$messages .= 'Occupation is a required field. Please try again.' . "<br>n";
else:
$occupation = htmlentities($_POST['Occupation']);
endif;
if(!isset($_POST['Current_Age'])
|| is_empty($_POST['Current_Age']) ):
$messages .= 'Current Age is a required field. Please try again.' . "<br>n";
else:
$current_age = htmlentities($_POST['Current_Age']);
endif;
if(strlen($messages) == 0):
$output = $_POST['First_Name'];
$output .= ', who is a ';
$output .= $_POST['Current_Age'];
$output .= '-year-old ';
$output .= $_POST['Occupation'];
$output .= ', ...';
$first_name = '';
$occupation = '';
$current_age = '';
endif;
endif;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Submit to Self</title>
</head>

<body>
<?php
if(strlen($messages) > 0):
echo '<p style="color:red;">' . $messages . "</p>n";
endif;
?>
<form action="" method="post">
<p>First name: <input type="text" name="First Name" size="20"
value="<?=$first_name?>"><br>
Occupation: <input type="text" name="Occupation" size="20"
value="<?=$occupation?>"><br>
Current age: <input type="text" name="Current Age" size="20"
value="<?=$current_age?>"></p>
<p><input type="submit" value="Submit" alt="Submit"></p>
</form>
<p>&nbsp;</p>
<?php
if(strlen($output) > 0):
echo '<p>' . $output . "</p>n";
endif;
?>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@bittsenauthorDec 23.2006 — Javascript works, right?

~LOL~

I have been working on it for an hour or so to get it to do what I want. I have a small problem though

I want the finished product to show HTML formatting.

I am using "xmp" a s a command to get the HTML to show in the static text but it inserts carriage returns and such. Is there any way to fix this?

Thanks for helping
Copy linkTweet thisAlerts:
@so_is_thisDec 23.2006 — Don't know what "xmp" is, sorry.
Copy linkTweet thisAlerts:
@bittsenauthorDec 23.2006 — <xmp>

is a command to allow HTML coding to show in a browser.

It is the only way I know how to show the HTML when the POST function is used.
Copy linkTweet thisAlerts:
@so_is_thisDec 23.2006 — OK, I looked it up and find this notation:
Use of this element is no longer recommended. Use the [URL=http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/pre.asp]PRE[/URL] or [URL=http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/samp.asp]SAMP[/URL] element instead.[/QUOTE]
Copy linkTweet thisAlerts:
@bittsenauthorDec 23.2006 — WOW, both PRE and SAMP messed up the function of the form.

Any other suggestions?

It IS supposed to be <PRE></PRE> and <SAMP></SAMP> correct?
Copy linkTweet thisAlerts:
@so_is_thisDec 23.2006 — Yes, but you wouldn't want put a form inside those tags if the form is supposed to function as a form. I guess I don't understand what you are doing. ? How about attaching a screen shot? You can also convert the < and > characters to their HTML entity counterparts to show HTML as text.
Copy linkTweet thisAlerts:
@bittsenauthorDec 23.2006 — http://www.thereef.ws/members/Infern/scripttest.shtml

it's ugly right now, but

Well.....it's just ugly

~LOL~

I do appreciate your help
Copy linkTweet thisAlerts:
@so_is_thisDec 23.2006 — Just need to remove this line from your script because you did not use this form field name:

if(ValueMissing(f.elements['First Name'])) return false;

Otherwise... What's wrong with it?

EDIT: Oh, I see. You've just got too many <xmp>'s in there.
Copy linkTweet thisAlerts:
@bittsenauthorDec 23.2006 — ~LOL~

I think I will just go with converting the < and > characters to their HTML entity counterparts to show HTML as text.

It seems easier that way

Thanks very much
Copy linkTweet thisAlerts:
@so_is_thisDec 23.2006 — This is closer to what you want for that section:
[code=html]
<center>
<table width="500px" bgcolor="dddddd"><tr><td style="text-align: left;">

<script type="text/javascript">
<!--//
var str = self.location.search.substr(1);
if (str.length > 0)
{
var _get = str.parsePairs();
str = '<body bgcolor="' + _get['bgcolor1'] + '" background="' + _get['mainbackground'] + '">n';
str += '<center>n';
str += ' <table width="90%" bordercolor="' + _get['bordercolor1'] + '" borderwidth="' + _get['borderW1'] + '">n';
str += ' <tr><td bgcolor="' + _get['bgcolor2'] + '" background="' + _get['background2'] + '">n';
str += ' <center>n';
str += ' <table width="90%" bordercolor="' + _get['bordercolor2'] + '" borderwidth="' + _get['borderW2'] + '">n';
str += ' <tr><td background="' + _get['background3'] + '">n';
str += ' <center>n';
str += ' <table bordercolor="' + _get['bordercolor3'] + '" borderwidth="' + _get['borderW3'] + '">n';
str += ' <tr><td background="' + _get['background4'] + '">n';
str += ' <p>' + _get['Your Name'] + ', a ' + _get['Current Age'] + '-year-old ' + _get['Occupation'] + ', ...' + '</p>n';
str += ' </td></tr>n';
str += ' </table>n';
str += ' </center>n';
str += ' </td></tr>n';
str += ' </table>n';
str += ' </center>n';
str += ' </td></tr>n';
str += ' </table>n';
str += '</center>n';
str += '</body>n';
document.writeln('<pre>', str.replace(/</g, '&lt;').replace(/>/g, '&gt;'), '</pre>');
}
//-->
</script>

</td></tr></table>
</center>[/code]
Copy linkTweet thisAlerts:
@bittsenauthorDec 23.2006 — Show off!!!!

~LOL~

Thanks......

It gives me the jumping point I need

Now, off to making it purty.

I owe ya a doughnut!!
Copy linkTweet thisAlerts:
@so_is_thisDec 23.2006 — Bavarian Cream Filled!

Salud!
×

Success!

Help @bittsen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...