/    Sign up×
Community /Pin to ProfileBookmark

Passing values from javascript to php form mailer

I have this form that creates a input field dynamically, only problem is, the input field doesn’t pass the values to the php script. Im assuming i need to either code the javascript to populate the variable in the php script or vice versa im stuck on this??? any ideas the cript is below:

Php script:

[code=php]
<?php

$EmailTo = “[email protected]”;
$Youngest = Trim(stripslashes($_POST[‘names[]’]));

// prepare email body text
$Body .= “Extra names: “;
$Body .= $Youngest;
$Body .= “n”;

// send email
$success = mail($EmailTo, $Body);

// redirect to success page
if ($success){
print “<meta http-equiv=”refresh” content=”0;URL=ok.htm”>”;
}
else{
print “<meta http-equiv=”refresh” content=”0;URL=error.htm”>”;
}
?>
[/code]

the form is:

[code]
<form action=”cgi/guestlistForm.php” method=”post”>

<div id=”firstname”>
<p>
<label for=”name_3″ title=”guests”>+ Guests full name :</label>
<input class=”inputField” type=”text” name=”names[]” id=”name_3″>
</p>
</div>

<div>
<p><a href=”javascript://” id=”addperson”>+ Add another guests</a></p>
<script type=”text/javascript”>
var count = 2; // The one that’s already there is 1
Event.observe(‘addperson’, ‘click’, function() {
count++
var namefield = ‘<div id=”firstname”><p><label for=”name_’+count+'” guests”>Full name:</label><input class=”inputField” name=”names[]” type=”text” id=”name_’+count+'” /></p></div>’;
new Insertion.Bottom(‘firstname’, namefield)
});
</script>
</div>
<input class=”submit” name=”image” id=”image” type=”image” onmouseover=”src=’images/submit_over.gif'”onmouseout=”src=’images/submit.gif'” value=”Send” src=”images/submit.gif”/>
</div>

</form>[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 12.2007 — The name/value pairs have to be picked up by the $_POST array in the php script.

A simple example: http://www.tizag.com/phpT/forms.php
×

Success!

Help @developing 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...