| View previous topic :: View next topic |
| Author |
Message |
joshcxa 100+ Club

Joined: 18 Aug 2004 Posts: 156 Location: Australia
|
Posted: Wed Jul 27, 2005 2:02 pm Post subject: Mandatory Fields |
|
|
How do I make an alert popup when a required field isn't filled in.
At the moment, info from my forms get sent even if the required fields aren't filled in. |
|
| Back to top |
|
 |
|
|
webmaster Site Admin

Joined: 17 Aug 2004 Posts: 3642 Location: Sweden
|
Posted: Wed Jul 27, 2005 2:39 pm Post subject: Re: Mandatory Fields |
|
|
PHP: <?php if($_POST[feildname] == "") {
echo "Your forgot to enter something in feildname";
}
?>
Last edited by webmaster on Wed Jul 27, 2005 4:07 pm; edited 1 time in total |
|
| Back to top |
|
 |
joshcxa 100+ Club

Joined: 18 Aug 2004 Posts: 156 Location: Australia
|
Posted: Wed Jul 27, 2005 4:02 pm Post subject: Re: Mandatory Fields |
|
|
cool thanks..
does that bring up an alert box? |
|
| Back to top |
|
 |
webmaster Site Admin

Joined: 17 Aug 2004 Posts: 3642 Location: Sweden
|
Posted: Wed Jul 27, 2005 4:08 pm Post subject: Re: Mandatory Fields |
|
|
No it only shows the text: You forgot to enter something in fieldname.
But just change what it should echo, you can add html code in there to. |
|
| Back to top |
|
 |
joshcxa 100+ Club

Joined: 18 Aug 2004 Posts: 156 Location: Australia
|
Posted: Thu Jul 28, 2005 2:35 am Post subject: Re: Mandatory Fields |
|
|
| so i can chuck javascript in the echo? |
|
| Back to top |
|
 |
ReFredzRate 1000+ Club

Joined: 20 Aug 2004 Posts: 2186 Location: Netherlands
|
Posted: Thu Jul 28, 2005 5:57 am Post subject: Re: Mandatory Fields |
|
|
| Yes, as far as I know the PHP will be compiled, outputting pure HTML. So if you chuck HTML/Javascript/whatever in it, it will be treated the same way as you were coding a page in plain HTML or Javascript. |
|
| Back to top |
|
 |
webmaster Site Admin

Joined: 17 Aug 2004 Posts: 3642 Location: Sweden
|
Posted: Thu Jul 28, 2005 9:16 am Post subject: Re: Mandatory Fields |
|
|
And to make it even easier you can end the php, write the javascript as you want and then start the php again. Like this:
PHP: <?php if($_POST[feildname] == "") { ?>
Standard HTML or Javascript here!
<?php
}
?>
|
|
| Back to top |
|
 |
joshcxa 100+ Club

Joined: 18 Aug 2004 Posts: 156 Location: Australia
|
Posted: Thu Jul 28, 2005 1:59 pm Post subject: Re: Mandatory Fields |
|
|
| but the info will still send though...how do i stop that? |
|
| Back to top |
|
 |
webmaster Site Admin

Joined: 17 Aug 2004 Posts: 3642 Location: Sweden
|
Posted: Thu Jul 28, 2005 2:15 pm Post subject: Re: Mandatory Fields |
|
|
If you set the name on the submit-button to: hello
PHP: <?php
if(isset($_POST['hello'])) {
if($_POST['url'] == "") { ?>
You forgot the enter something in the url-field
<?php
} elseif($_POST['mail'] == "") { ?>
You forgot the enter something in the mail-field
<?php
} else {
echo "The url is: " . $_POST['url'] . " and the mail is: " . $_POST['mail'];
}
} else { ?>
<form method......
........................
........................
</form>
<?php
}
?>
|
|
| Back to top |
|
 |
|