Solved

Form Submission based on PHP IF Statement

Posted on 2011-09-07
4
335 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 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now