pcw Posted March 5, 2009 Author Share Posted March 5, 2009 Thats great Keith, thanks very much for your help Link to comment https://forums.phpfreaks.com/topic/147802-solved-generate-form-fields/page/2/#findComment-777502 Share on other sites More sharing options...
pcw Posted March 5, 2009 Author Share Posted March 5, 2009 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 https://forums.phpfreaks.com/topic/147802-solved-generate-form-fields/page/2/#findComment-777553 Share on other sites More sharing options...
pcw Posted March 5, 2009 Author Share Posted March 5, 2009 Any idea on how I print these? Link to comment https://forums.phpfreaks.com/topic/147802-solved-generate-form-fields/page/2/#findComment-777639 Share on other sites More sharing options...
kickstart Posted March 6, 2009 Share Posted March 6, 2009 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 https://forums.phpfreaks.com/topic/147802-solved-generate-form-fields/page/2/#findComment-777759 Share on other sites More sharing options...
pcw Posted March 6, 2009 Author Share Posted March 6, 2009 Hi, I would like to print the result of every field submitted, how is this done? Link to comment https://forums.phpfreaks.com/topic/147802-solved-generate-form-fields/page/2/#findComment-778057 Share on other sites More sharing options...
kickstart Posted March 6, 2009 Share Posted March 6, 2009 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 https://forums.phpfreaks.com/topic/147802-solved-generate-form-fields/page/2/#findComment-778077 Share on other sites More sharing options...
pcw Posted March 6, 2009 Author Share Posted March 6, 2009 That done the trick. Thanks very much for your help Keith, you been a star Link to comment https://forums.phpfreaks.com/topic/147802-solved-generate-form-fields/page/2/#findComment-778080 Share on other sites More sharing options...
pcw Posted March 6, 2009 Author Share Posted March 6, 2009 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 https://forums.phpfreaks.com/topic/147802-solved-generate-form-fields/page/2/#findComment-778464 Share on other sites More sharing options...
kickstart Posted March 6, 2009 Share Posted March 6, 2009 Hi Possibly be easiest to do that by using 2 hidden fields, one for name and one for type. Be a pretty easy mod to do. All the best Keith Link to comment https://forums.phpfreaks.com/topic/147802-solved-generate-form-fields/page/2/#findComment-778578 Share on other sites More sharing options...
pcw Posted March 6, 2009 Author Share Posted March 6, 2009 Its ok, done it now, thanks Link to comment https://forums.phpfreaks.com/topic/147802-solved-generate-form-fields/page/2/#findComment-778585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.