Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
PHP Self Submitting Form
Old 05-23-2006, 06:05 PM PHP Self Submitting Form
Super Talker

Posts: 104
Location: San Diego, Ca
Trades: 0
How would i go about making a PHP self submitting form that would accept HTML for input into a text box and output the result of the html onto the bottom of the page.. much like www.practiceboard.com ?

This is my basic form (i'm not worried about validation or security at this point.. just trying to get it to work. And yes... this is being posted on a server which has php up and running.)

PHP Code:
<?php
$Fname 
$_POST["Fname"];
$Lname $_POST["Lname"];
$gender $_POST["gender"];
$food $HTTP_POST_VARS["food"];
$quote $_POST["quote"];
$education $_POST["education"];
$TofD $_POST["TofD"];
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br />
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />
Please choose type of residence:<br />
Steak:<input type="checkbox" value="Steak" name="food[]"><br />
Pizza:<input type="checkbox" value="Pizza" name="food[]"><br />
Chicken:<input type="checkbox" value="Chicken" name="food[]"><br />
<textarea rows="5" cols="20" name="quote" wrap="physical">Enter your favorite quote!</textarea><br />
Select a Level of Education:<br />
<select name="education">
<option value="Jr.High">Jr.High</option>
<option value="HighSchool">HighSchool</option>
<option value="College">College</option></select><br />
Select your favorite time of day:<br />
<select name="TofD" size="3">
<option value="Morning">Morning</option>
<option value="Day">Day</option>
<option value="Night">Night</option></select><br />
<input type="submit" value="submit" name="submit">
</form>
as of right now.. this form just refreshes the page with no new data.
__________________
Porch Monkey. And that's the truth.
iqchicken is offline
View Public Profile
 
 
Register now for full access!
Old 05-23-2006, 10:23 PM Re: PHP Self Submitting Form
Average Talker

Posts: 19
Trades: 0
well the simple problem here is that you have the action set to $PHP_SELF, but you never echo the variables. You declared and gave all the $_POST variables values but failed to echo them onto the page anywhere.
PhorumBored is offline
View Public Profile
 
Old 05-23-2006, 10:42 PM Re: PHP Self Submitting Form
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
PHP Code:
<html>
   <body>
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
         <textarea name="html"></textarea><br />
         <input type="submit" /><br />
      </form>
      Preview:<br />
      <?php if(isset($_POST['html'])) echo stripslashes($_POST['html']); ?>
   </body>
</html>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
View Public Profile
 
Old 08-01-2009, 10:08 PM Re: PHP Self Submitting Form
Novice Talker

Posts: 9
Trades: 0
Well the problem with above script is it always execute the php snippet regardless of form has been submitted or not each time when page loads. use of isset() fuction to avoid that is not suitable for some application..

Has anyone found solution something like form triggers event, and then we use that trigger value in php script to determine whether form has been submitted or not.
__________________

Please login or register to view this content. Registration is FREE
treemonster19 is offline
View Public Profile Visit treemonster19's homepage!
 
Old 08-01-2009, 10:16 PM Re: PHP Self Submitting Form
Novice Talker

Posts: 9
Trades: 0
<?PHP
if(isset($_POST['form']) && $_POST['form']=='true')
{
/// php code to retrieve the remaining variables;
///
///
}
?>

<form>
<input name="username" type="text" id="username" />
<input name="password" type="text" id="password" />
<input name="form" type="hidden" id="form" value="true">
<input type="submit" name="Submit" value="Submit" />
</form>
__________________

Please login or register to view this content. Registration is FREE
treemonster19 is offline
View Public Profile Visit treemonster19's homepage!
 
Old 08-03-2009, 08:14 AM Re: PHP Self Submitting Form
Novice Talker

Posts: 13
Trades: 0
Actually, just do:

Code:
if (!empty($_POST)) { .. }
Also, make sure to htmlspecialchar those variables on output..

Code:
<input name="username" type="text" value="<?php echo htmlspecialchars($_POST['username']); ?>" />
premiumscripts is offline
View Public Profile
 
Closed Thread     « Reply to PHP Self Submitting Form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16783 seconds with 12 queries