Jump to content

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

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.