Jump to content

[SOLVED] Make array usable outside switch statement


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.