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  :)

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Hi,

 

Is it possible to split $DisplayInfo so it prints:

 

Field Name and Field Type separately? I need to do this so I can write the results to mysql database. Cant seem to figure out how to split it.

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.