/    Sign up×
Community /Pin to ProfileBookmark

passing form details through php

hey guys,
im pretty new to php, so please excuse the stupid question.

ive made use of a captcha image within my mail form named form1.
basically when the user submits the form, the details are sent to form.php which checks that the captcha is right.

my issue (only small) is how to send the details of form1 from form.php to form2mail.php (the mailer).

my form.php is as follows…

<?php
session_start();
if(($_SESSION[‘security_code’] == $_POST[‘security_code’]) && (!empty($_SESSION[‘security_code’])) ) {
// this is basically what i want to mimic. what is the PHP syntax for this?
echo ‘<form name=”form1″ method=”post” action=”form2mail.php”>’;
unset($_
SESSION[‘security_code’]);
} else {
// display error….

appreciate the help guys!

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ZnupiJul 04.2008 — You can do both things in one file. Or, you can use [url=http://www.php.net/include/]include[/url] or [url=http://www.php.net/require/]require[/url]. Let us know if you figure it out ?
Copy linkTweet thisAlerts:
@broncozrJul 04.2008 — russ,

I usually put a hidden element in the form to give the page an idea as to what should be done.

e.g.

<form>

<input type='hidden' id='cmd' name='cmd' value=''></input>

<input type=button value='Submit' onclick='validate();'></input>

etc.

</form>


When the form is submitted (to the same page---action='form.php'), I usually use Javascript (JS) to set the value of the hidden element, 'cmd'.

<script language='Javascript'>

<!--

function validate()

{

if(something is wrong)

{

alert('show error');

}

etc.

else

{

submitTheForm();

}

function submitTheForm()

{

// set the hidden element's value so that

// it can be read when the page reloads....

// you can then use PHP $_REQUEST['cmd']

// to read the value on the reloaded page

// and take the appropriate action.....

document.form1.cmd.value='send';
document.form1.submit();

}

The PHP on the reloaded page would be something like:

if($_REQUEST['cmd']=='send')

{

// send the mail....

}


I've recently done an e-mail form, and I used captchas.net and recaptcha.net services. Just a suggestion. Also, the Pear (PHP) Mail package does some validation of the email-form fields to hinder header injection by hackers. Here's the link to Pear
Copy linkTweet thisAlerts:
@ZnupiJul 05.2008 — [b]broncozr[/b], that's the worst idea possible. What happens when a user with deactivated javascript visits your site? Your whole form won't work. And you didn't even answer [b]russOner[/b]'s question, you just gave him a (really) bad idea. If you want to handle everything in one script, you can do this:
[code=php]
<?php

if (empty($_POST)) {
// If nothing was submitted, display form, etc.
}
else {
// Something was submitted, start error checking and handling the data
}

?>
[/code]

Also.. please use [code] or [code=php] or similar tags to enclose your code.
Copy linkTweet thisAlerts:
@broncozrJul 06.2008 — I gave him a solution that allows his page to pass meaningful info. to itself---it doesn't just check to see if something was posted. LOLOLOL You put an if/else statement on the page and told him to let us know if he figured out something.

You can design without JS if you want to. ?
Copy linkTweet thisAlerts:
@russOnerauthorJul 06.2008 — thanks for the help guys!

i just included the form2mail script within a if else statement.

you guys rock!
Copy linkTweet thisAlerts:
@ZnupiJul 06.2008 — I gave him a solution that allows his page to pass meaningful info. to itself---it doesn't just check to see if something was posted. LOLOLOL You put an if/else statement on the page and told him to let us know if he figured out something.

You can design without JS if you want to. ?[/QUOTE]

Well, he figured it out, with what I told him. And he (hopefully) didn't use your javascript thing which had nothing to do with his question, and which is extremely bad.
×

Success!

Help @russOner 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.24,
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,
)...