Solved

Form Submission based on PHP IF Statement

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SVG and IE11 2 15
Link Anchor Not working 9 42
Jquery HTML() with ajax... replacing content 2 26
PHP Curl Problem 10 31
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
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?
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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…

679 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