Jump to content

[SOLVED] Generate form fields


pcw

Recommended Posts

Just one more question, is it possible to print the formfield name and type, above the previewarea?

 

eg. After adding formfield and fieldtype, it prints:

 

Field Name: First Name  Field Type: Text Field

 

I have tried:

 

<?php 
foreach($_POST as $name => $value)
	{
	print "$value";
	}
?>

 

But it prints a lot of input boxes. Thanks for your help  :)

 

 

Any idea on how I print these?

 

Do you want this just for the last form fields you generated (easy) or a list if you add more than one form field (more difficult as this would require storing the data seperatly for the next time it was displayed).

 

All the best

 

Keith

Hi

 

I suspect the easiest way to do it, which is a bit of a bodge, would be to put the info into a hidden field, and each time display the contents as text where you want (plain text isn't returned with the form, but the contents of the hidden field would be).

 

Lile this:-

 

<?php

$optionCnt = 0;

if ($_POST['addoption'])
{
echo '<form name="makeformfield" method="post">
Field Name: <input type="text" name="fieldname" value="'.$_POST['fieldname'].'">
Field Type: <select name="fieldtype">
<option>Text Field</option>
<option>Text Area</option>
<option>Radio Button</option>
<option>Checkbox</option>
<option selected="selected">Select</option>
</select><br />';
foreach($_POST as $field => $value)
{
	if (substr($field,0,11) == "optionvalue")
	{
		$optionCnt++;
		echo "<input type='text' name='$field' value='$value' /><br />";
	}
}
echo "<input type='text' name='optionvalue$optionCnt' value='' /><br />";		
$DisplayInfo = $_POST['hiddendata'];
echo '<input type="hidden" name="hiddendata" value="'.$DisplayInfo.'" />';
echo "$DisplayInfo<br />";
echo stripslashes('<textarea cols="60" rows="5" name="previewarea" >'.$_POST['previewarea'].'</textarea>');
echo '<input type="submit" name="submit" value="submit">
<input type="submit" name="addoption" value="addoption">';
}
else
{
echo '<form name="makeformfield" method="post">
Field Name: <input type="text" name="fieldname">
Field Type: <select name="fieldtype">
<option>Text Field</option>
<option>Text Area</option>
<option>Radio Button</option>
<option>Checkbox</option>
<option>Select</option>
</select><br />';
echo "<input type='text' name='optionvalue$optionCnt' value='' />";		
if ($_POST['submit'])
{

	$option = $_POST['field_options'];
	$type = $_POST['fieldtype'];
	$name = $_POST['fieldname'];

	if ($type == 'Text Field')
	{
	$NewField = '<input type="text" name="'.$name.'" />';
	}
	if ($type == 'Text Area')
	{
	$NewField = '<textarea cols="5" rows="4" name="'.$name.'"></textarea>';
	}
	if ($type == 'Radio Button')
	{
	$NewField = '<input type="radio" name="'.$name.'" />';
	}
	if ($type == 'Checkbox')
	{
	$NewField = '<input type="checkbox" name="'.$name.'" />';
	}
	if ($type == 'Select')
	{
		$NewField = '<select name="'.$name.'" />'.chr(13);
		foreach($_POST as $field => $value)
		{
			if (substr($field,0,11) == "optionvalue")
			{
				$NewField .= '<option>'.$value.'</option>'.chr(13);
			}
		}
		$NewField .= '</select>';
	}
	echo '<p>view code:</p>';
	$DisplayInfo = $_POST['hiddendata']."<br />Field Name: $name  Field Type: $type";
	echo '<input type="hidden" name="hiddendata" value="'.$DisplayInfo.'" />';
	echo "$DisplayInfo<br />";
	echo stripslashes('<textarea cols="60" rows="5" name="previewarea" >'.$_POST['previewarea'].chr(13).$NewField.'</textarea>');
	echo '<input type="submit" name="submit" value="submit">
	<input type="submit" name="addoption" value="addoption">';
}
else
{	
	echo stripslashes('<textarea cols="60" rows="5" name="previewarea" ></textarea>');
	echo '<input type="submit" name="submit" value="submit">
	<input type="submit" name="addoption" value="addoption">';
}
}

echo '</form>';

?>

 

All the best

 

Keith

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.