/    Sign up×
Community /Pin to ProfileBookmark

how to retrieve dynamic form data for php mail

Hi everyone. I have a issue. Basically I have no clue how to send form data, which has been dynamically created to my php mail script. I have no problems sending the details of the original form in the mail, however, when it comes to retrieving details from dynamically created forms, i have no clue! here is my javascript function to create the dynamic form.

Javascript:

<script type=”text/javascript”>
var counter = 0;

function moreFields() {
counter++;

var newFields = document.getElementById(‘childinfo’).cloneNode(true);
newFields.id = ‘clone + counter’;
newFields.style.display = ‘block’;

var newField = newFields.childNodes;
for (var i=0;i<newField.length;i++) {
var theName = newField[i].name
if (theName){

newField[i].name = theName.substring(0,theName.length-1) + counter;

}
var insertHere = document.getElementById(‘inject’);

insertHere.parentNode.insertBefore(newFields,insertHere);

//document.getElementById(‘titles’).innerHTML = 1 + counter;
}

}
</script>

html:
<div align=”left” id=”page3″>
<table width=”635″ border=”0″>
<tr>
<th colspan=”2″ scope=”col”><div align=”left”>Section 3: Your child/children’s information <br /></div></th>
</tr>
</table><br />
<div id =”childinfo” style=”display: none”>

<table width=”635″ border=”0″ >

<tr>
<td><u><strong>Child #
<label id=”titles”>1</label>
</strong>
<label id=”titles”></label></u></td>
<td>&nbsp;</td>
</tr>
<tr>
<td width=”157″><strong>Title: </strong></td>
<td width=”468″><select name=”select2″ size=”1″>
<option value=”0″>Please Select…</option>
<option>Mr</option>
<option>Mrs</option>
<option>Miss</option>
<option>Ms</option>
</select></td>
</tr>
<tr>
<td><strong>First Name: <br />
</strong></td>
<td><input type=”text” name=”textfield29″ /></td>
</tr>
<tr>
<td><strong>Surname:</strong></td>
<td><input type=”text” name=”textfield30″ /></td>
</tr>
<tr>
<td><strong>D.O.B:</strong></td>
<td><input name=”textfield52″ type=”text” onfocus=”if (this.value == ‘dd/mm/yyyy’) {this.value=”}” onblur=”if(this.value == ”) { this.value=’dd/mm/yyyy’};return checkdate(this);” value=”dd/mm/yyyy” maxlength=”10″/></td>
</tr>
<tr>
<td><strong>Chosen sport: </strong></td>
<td><select name=”select4″ size=”1″>
<option>Please Select…</option>
<option>Football</option>
<option>Tennis</option>
<option>Basketball</option>
<option>Athletics</option>
<option>Badminton </option>
</select> </td>
</tr>
</table>
<input type=”button” value=”Remove child” onclick=”this.parentNode.parentNode.removeChild(this.parentNode);” /></div>

<table width=”635″ border=”0″ >
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>

</tr>
<span id=”inject”></span>

<tr>

<td><input type=”button” name=”Button” onclick= “collapseElem(‘page3’); expandElem(‘page2’); scrollTo(0,0);” value=”&lt; Previous” />
<input type=”button” name=”Button7″ onclick=” moreFields()” value=”Add child” />
<input name=”Button” type=”button” value=”Next &gt;” /></td>
<td>&nbsp;</td>

</tr>
</table>

</div>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SrWebDeveloperDec 17.2009 — Please next time wrap your source in the PHP or code tags, thanks.

Anyway, in PHP as you know all submitted form fields end up in $_POST so get the name/value of only your cloned fields (simple example):

[code=php]foreach ($_POST as $key=>$value) {

if (strpos($key,"clone")) {
// ... do whatever ... $key is the current field ID, i.e. "clone 1" and $value is the value of that field of course.
}

}
[/code]


I don't think you meant to do this, btw:

[CODE]newFields.id = 'clone + counter';[/CODE]

That should probably be:

[CODE]newFields.id = 'clone ' + counter; // or similar[/CODE]

Obviously it's up to you to customize and process the cloned data as you see fit. I didn't test the code, who knows if it works, and come to think of it I might use preg_match instead of strpos, but you get the idea. That's all I'm tryin' to show ya here with this simple example.

-jim
Copy linkTweet thisAlerts:
@sokandauthorDec 18.2009 — thank you, il give that a go
×

Success!

Help @sokand spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...