Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Form Submission based on PHP IF Statement

Posted on 2011-09-07
4
Medium Priority
?
360 Views
Last Modified: 2012-05-12
I have an html form that I have used javascript and PHP to validate.  I need to submit the results of the form via email to my client, and redirect the user to PayPal for payment.  It is a tournament entry form.

In the process page, I have a section that basically looks for a VALID FORM, and if that condition is met, sends the email to my client, and I need it to process the PayPal form with the variables for payment.  There is no specific "click action" here, so I don't think onclick is the way to go here.  However, my javascript knowledge is weak.

Looking at the code snippet below, how would you get this form to submit if ($valid_form) returns TRUE?

// check if form is valid
	if ($valid_form)
	{
		// create message
		$message = "Name: " . $form['name'] . "\n";
		$message .= "Phone: " . $form['phone'] . "\n";
		$message .= "Address: " . $form['address'] . "\n";
		$message .= "City: " . $form['city'] . "\n";
		$message .= "State: " . $form['state'] . "\n";
		$message .= "Zip Code: " . $form['zipCode'] . "\n";
		$message .= "Email Address: " . $form['email'] . "\n\n";		
		
		$headers = "From: WEST PARK LANES Online Tournament Entry <webmaster@westparklanes.com>\r\n";
		$headers .= "X-Sender: <webmaster@westparklanes.com>\r\n";
		$headers .= "X-Mailer: PHP/". phpversion() ."\r\n";
		$headers .= "Reply-To: " . $form['email'];
		
		// send email
		mail($to, $subject, $message, $headers);
		
		// payPal Redirect
		?>
        <!-- send the PayPal form -->
<form id="scratchShootout" name="scratchShootout" method="post" action="https://www.paypal.com/cgi-bin/webscr">
		<input type="hidden" name="cmd" value="_xclick" />
		<input type="hidden" name="premier" value="darryl.james@drurysouthwest.com" />
		<input type="hidden" name="item_name" value="2011 Scratch Shootout Tournament Entry for <?php echo $_SESSION['name']; ?>" />
		<input type="hidden" name="amount" value="<?php echo $_SESSION['totalAmount']; ?>" />
		<input type="hidden" name="currency_code" value="USD" />
		<input type="hidden" name="lc" value="US" />
		<input type="hidden" name="return" value="http://www.westparklanes.com/subpage.php?content=thankYou/tournamentThankYou" />
		<input type="hidden" name="cancel_return" value="http://www.westparklanes.com" />
		<input type="hidden" name="receiver_email" value="dennis.hacker@offthesheet.com" />
		<input type="hidden" name="no_shipping" value="1" />
		<input type="hidden" name="no_note" value="0" />
		</form>
                
		<?php
	}
	else
	{
		include('includes/onlineEntries/2011scratchShootoutForm.inc.php');
	}

Open in new window

0
Comment
Question by:DennisHacker
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
cstsang earned 2000 total points
ID: 36500525
Add the following script in line 37:
<script language=javascript>document.scratchShootout.submit();</script>

Open in new window

0
 

Author Closing Comment

by:DennisHacker
ID: 36500622
If you wouldn't mind...explain to me why that didn't work before the form?  I had it in at Line 22 before and the script stalled.

As I already said, I'm weak at javascript, but trying to learn.

Your solution worked awesomely.
0
 

Author Comment

by:DennisHacker
ID: 36500647
By the way...my subscription to this site pays off every time I use it.  I can't imagine the time that it saves me when I get a solution from one of you guys.

I have a guy who helps me on my scripts as well...but I can't count on him.  I can count on you, within minutes.
0
 
LVL 7

Expert Comment

by:cstsang
ID: 36500808
In the browser point of view, it doesn't knows the form before receive the tag <form>, so you need to place the script after the <form>.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question