Solved

Form Submission based on PHP IF Statement

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to dynamically set the form action using jQuery.

770 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