Jump to content

[SOLVED] PHP Form Help


jlm

Recommended Posts

First off, let me start out by saying I know just enough about PHP to be dangerous.  My normal use if to take an existing PHP form and modify to do what I want, however over time I have started to create my own from scratch.

 

Here's the issue I have right now.  I have a form that lets users enter data and then when they submit the form, that data is emailed to me.  Simple, right.  Well, right now there are fields for them to enter the data for 5 projects on the same form.  What I want to do is have a button that will basically say "click to here to add another field".  When the button is clicked it adds another set of fields for them to enter information about a sixth project.  Click the button again, adds another set of fields for information about a seventh project.....and so forth.  I hope this makes sense.

 

Now my question is, how do I go about setting up this script that will allow me to implement this feature in my form.  Any help at all anyone can provide will be greatly appreciated.

 

Thanks,

 

John

Link to comment
Share on other sites

here's one way

<?php
if (isset($_GET['sub']))
{
    echo '<pre>', print_r($_GET, true), '</pre>';
}
?>
<html>
<head>
<meta name="generator" content="PhpED Version 4.5 (Build 4513)">
<title>sample</title>
<script language="javascript">
         function addfields()
         {
             var newline = "Project ID <input type='text' name='projID[]' size='6'> Cost <input type='text' name='cost[]' size='8'><br>";
             var extra = document.getElementById("extra");
             extra.innerHTML = extra.innerHTML + newline;
         }
</script>
</head>
<body>
<form>
      Project ID <input type="text" name="projID[]" size="6"> Cost <input type="text" name="cost[]" size="8"><br>
      Project ID <input type="text" name="projID[]" size="6"> Cost <input type="text" name="cost[]" size="8"><br>
      Project ID <input type="text" name="projID[]" size="6"> Cost <input type="text" name="cost[]" size="8"><br>
      Project ID <input type="text" name="projID[]" size="6"> Cost <input type="text" name="cost[]" size="8"><br>
      Project ID <input type="text" name="projID[]" size="6"> Cost <input type="text" name="cost[]" size="8"><br>
      <div id="extra"></div>
      <input type="button" name="add" value="Add item"   onclick="addfields()"> <input type="submit" name="sub" value="Submit">
</form>
</body>
</html>

 

As there is no php involved I'll move this to the javascript forum

Link to comment
Share on other sites

Hmmm, for some reason (and I'm sure it's something I'm going) this is not working.  I've even tried to take exactly what you have and just use it as a test.  The form displays like this

<img src="http://mosssite.com/testing/form.jpg/>

and the add item button does not work.  Again I thank you very much for you help and I'm sure I've done something wrong.  Basically I've just pasted what you gave me into a file and named it test.html, put it on my webserver and that's it.  Let me know if you any more information will help.

 

Thanks

Link to comment
Share on other sites

  • 1 month later...
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.