Jump to content

[SOLVED] Dynamic forms?


B34ST

Recommended Posts

Hi,

I have a form where users can input step by step guides. There is no limit on the number of steps for each guide so instead of displaying a set amount of input boxes I want to add just one named step1 then if the user requires a step 2 they can click add another step and another box pops up under step 1 named step 2 etc I dont want any of the informatin to be submited untill the user has stopped adding steps and clicks the submit button.

 

I am not sure if this can be done with php?

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/55872-solved-dynamic-forms/
Share on other sites

Well first of all you'd need a to make a button with an onclick:"" that triggers the function that adds another box in javascript. I'm gonna look something up on google for your specific needs and I'll keep you posted. (I don't know javascript but I'm always willing to learn myself).

Link to comment
https://forums.phpfreaks.com/topic/55872-solved-dynamic-forms/#findComment-276031
Share on other sites

Javascript/HTML

<script type="text/javascript">
function add_file(id, i) {
if (document.getElementById(id + '_' + i).innerHTML.search('uploadinputbutton') == -1) {
	document.getElementById(id + '_' + i).innerHTML = '<textarea class="uploadinputbutton" name="step[]"></textarea><br /><span id="' + id + '_' + (i+1) + '"><input type="button" value="Add Another Step" onClick="add_file(\'' + id + '\', ' + (i+1) + ');" /><\/span>\n';
}
}
<form action="view.php" method="post">
<textarea class="uploadinputbutton" name="step[]"></textarea>
<br>
<span id="file_1">
<input value="Add Another Step" onclick="add_file('file', 1);" type="button">
</span>
</form>

 

PHP (view.php)

<?php
echo '<ol>';
foreach($_POST['step'] as $step){
echo '<li>'.$step.'</li>';
}
echo '</ol>';
?>

Link to comment
https://forums.phpfreaks.com/topic/55872-solved-dynamic-forms/#findComment-276032
Share on other sites

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.