Solved

Form Submission based on PHP IF Statement

Posted on 2011-09-07
4
351 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 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…

627 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