Jump to content

[SOLVED] Make array usable outside switch statement


iarp

Recommended Posts

Hey,

 

index.php

switch($_GET['action']) {
	case 'contact-form':
		contactForm($_POST['name'], $_POST['email'], $_POST['phone'], $_POST['subject'], $_POST['comments']);
		break;
}

 

contactform function

...... cut everything above to save space.
if (empty($errors)) { //if everythings ok

	//Send e-mail with comments
	$body = "Name: " . $name . "\nPhone: " . $phone . "\nE-mail: " . $email . "\n\n" . $comments . " ";
	mail ('[email protected]', '[Website] '.$subject, $body, 'From: '.$email);

	echo '<h1>Thank-you!</h1><p>Your message was successfully sent,</p><p>If you had any questons we will try to respond ASAP.</p><br /></p>';
} else {
	return $errors;
}

 

furthur down the index.php page outside of the switch statement.

		<?php if(isset($errors)) displayErrors($errors); ?>

 

but $errors isn't usable outside of the switch statement. how can i make it globally usable. i tried global $temp1, $temp1 = $errors but didn't work.

 

TIA

contactForm($_POST['name'], $_POST['email'], $_POST['phone'], $_POST['subject'], $_POST['comments']);

should be

$errors = contactForm($_POST['name'], $_POST['email'], $_POST['phone'], $_POST['subject'], $_POST['comments']);

 

Scott.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.