Jump to content

[Help] I can't work out how to make a php file to make this <form> work..


Beanmen

Recommended Posts

Hi there, As the question says i tried several things but i can't work it out and my knowledge about php isn't that well.

 

<form>

                   <div class="text-box">

                    <label>

<input type="text" class="textbox" value="Your Name:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Your Name:';}">

</label>

<label>

<input type="text" class="textbox" value="Your Email:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Your Email:';}">

</label>

<div class="clear"></div>

</div>

<textarea value="Your Message:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Your Message:';}">Message</textarea>

<input type="submit" value="Send Message">

</form>

Link to comment
Share on other sites

You might be imagining this part of PHP wrong, 

 

PHP is Pre HyperText Processor, means, anything to do with PHP on page, will be processed before displaying HTML to user.

If you were to use PHP inside forms or let say, you wanted the form to be PHPized,

 

There could be two ways, as in my humble opininon,

<?php

	/* suppose we have some variables or data coming from PHP
	and we want to use them in HTML form - I am using hardcoding
	for simplicity and better understanding */
	
	$username = "theUser";
	$group = "admin";
	
	if($group == 'admin'){$isAdmin = true;} else {$isAdmin = false;}
	
	/* One way is as follows, to use the HTML inside PHP
	------------------------------------------------------------------------------
	I want so set a condition that if username is declared and user 
	group is admin, display the following form */
	
	if($isAdmin){
		echo("
			<form name='myForm' method='post' action='" . $_SERVER['PHP_SELF'] . "'>
				<input type='text' name='username' value = '" . $username . "' />
				<input type='submit' name='submitForm' value='Go' />
			</form>
		");
	} else {
		echo "You do not have permission to do blah blah";
	}
	
	/* Note that we have been doing everyhting of this inside <?php  ?> tag
	Now we will try to use the same form outside <?php tag */
?>

	<!--
		The Other way is outside php tag and using html straight
		Please not that how I am using <?php //code ?> tags inside
		the form to get data from PHP
	-->
	
	<?php if($isAdmin){ ?>
	<form name="myForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
		<input type="text" name="username" value="<?php echo $username; ?>" />
		<input type="submit" name="submitForm" value="Go" />
	</form>
	<?php } else { ?>
	<span>You do not have permission to do blah blah</span>
	<?php } ?>

I hope you will get it. :)

Link to comment
Share on other sites

@Beanmen : When you post code in the forum, you can use the 'code' button and paste your code in the popup that will appear, this way the code will have colour and will have a better format.

 

That being said, you should tell us:

  • The example you provided only has HTML, no PHP code. Do you have PHP installed on your computer? Or do you plan to code directly on a web server, for example by uploading PHP files with FTP? If you don't have PHP installed, you should check out XAMP (for Mac) or WAMP (for Windows), it will install PHP on your machine for you.
  • Do you want to create a contact form that will be send by email? It looks like this from your field names. If that's what you want, you can check out my tutorial: http://www.mogosselin.com/simple-php-contact-form/  (shamelessplug) or check Google for 'php contact form', I'm sure there is a ton of those. ;)
Link to comment
Share on other sites

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.