Jump to content


Form elements


2 replies to this topic

#1 curthard89

    Young Padawan

  • Members
  • Pip
  • 226 posts

Posted 31 March 2007 - 08:27 AM

I have a script that i wrote that at 1st gives you an input box where you type in a number and press generate steps. After pressing, it generates the steps and prints out textareas of how many steps you have type in, so if you typed 6 steps, it will print out 6 text areas.

My problem.

i have a field in mysql called tutorial, i want to be able to press submit and the content of the textareas to be merged together into a variable called

$tutorials = "content of textareas";

so then i can do the update mysql statment and put all the content from the textareas into the tutorial field in the DB.

Does anyone know how to do this? help would be appreciated, i can supply screenshots of the CMS (extremely hightech).

Cheers guys

Maybe ill give away the CMS to the guy who helps me ^_^

(gonna be more advanced then pixel2life :google:)

Edited by curthard89, 31 March 2007 - 08:35 AM.


#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 31 March 2007 - 09:20 AM

Well, there's an easy way I can think of.

For the name attribute of your textfields, make them in an array like this.
Assuming this is how you generate your number of steps and such.

<?php
// Get POST steps
$steps = (int)$_POST['steps'];
// Return string
$return = '';

// Loop number of steps needed and adds textareas
for($i = 0; $i < $steps; $i++){
$step_num = $i+1;
$return .= '<textarea name="stepcontent['.$step_num.']" id="stepcontent'.$step_num.'" rows="10" cols="10"></textarea>';
}

echo $return;
?>

That will echo out as many textareas as you need, and how ever you're doing it. Just be sure the name has the '[]' to indicate an array, and you can even make an associative array with it to make it easier, since I doubt your step numbering will start with 0 as in the array.

This way, you can then do this to combine your steps easily when the data is posted back.

<?php
// Safety precautions for posted data
// Strip HTML Function
function strip_html($data){
	$search = array('@<script[^>]*?>.*?</script>@si', // Strip Javascript
					'@<style[^>]*?>.*?</style>@siU',  // Strip Style Tags
					'@<[\/\!]*?[^<>]*?>@si',		  // Strip HTML tags
					'@<![\s\S]*?--[ \t\n\r]*>@'		  // Strip Multi-line Comments (CDATA)
	);
	return preg_replace($search, '', $data);
}

// Clean User Data Function
function cleandata($data){
	return trim(htmlspecialchars(strip_html($data)));
}

// Posted data
$steps_content = $_POST['stepcontent'];
// Complete content string
$full_content = '';

// Loop and add each step into the string, and clean it up
foreach($step_content as $step => $content)
$full_content .= cleandata($content);

# And your query goes here, just use $full_content to insert the tutorial data
?>


#3 curthard89

    Young Padawan

  • Members
  • Pip
  • 226 posts

Posted 31 March 2007 - 09:56 AM

nevermind, all is good, i got rid of the checking bit and u did a slight typo, cheers for the help

Edited by curthard89, 31 March 2007 - 10:26 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users