gazfocus Posted November 27, 2008 Share Posted November 27, 2008 I have a PHP form and for the date I've got 3 seperate boxes (one for dd, one for mm, and one for yyyy). 1. When the form is submitted, how do I make a variable containing all 3 in the format dd/mm/yyyy? I know it's $date=$_POST[dd] but then how do I add the other 2? 2. When the form comes up, instead of having labels, I've set the initial value as the label (ie date for the date box). Is it possible to make this text disappear once the curser goes into that box rather than having to manually delete it? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/134439-help-with-a-php-formtwo-quick-questions/ Share on other sites More sharing options...
Maq Posted November 27, 2008 Share Posted November 27, 2008 1) Concatenation. $final_date = "" . $_POST[dd] . "/" . $_POST[mm] . "/" . $_POST[yyyy] . ""; 2) Yes. You can do this using Javascript. onfocus="this.value = ( this.value == this.defaultValue ) ? '' : this.value;return true;"> Quote Link to comment https://forums.phpfreaks.com/topic/134439-help-with-a-php-formtwo-quick-questions/#findComment-699906 Share on other sites More sharing options...
gazfocus Posted November 27, 2008 Author Share Posted November 27, 2008 Sorry to sound dumb but where do I put that javascript code? What bits do I need to change to fit my form? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/134439-help-with-a-php-formtwo-quick-questions/#findComment-699911 Share on other sites More sharing options...
Maq Posted November 27, 2008 Share Posted November 27, 2008 Sorry to sound dumb but where do I put that javascript code? What bits do I need to change to fit my form? Can you post your form? Quote Link to comment https://forums.phpfreaks.com/topic/134439-help-with-a-php-formtwo-quick-questions/#findComment-699914 Share on other sites More sharing options...
gazfocus Posted November 27, 2008 Author Share Posted November 27, 2008 It's still a working process. I've put the echos in but haven't got it entered into the database yet. Here it is: <?php if ($_POST[viewed] != "yes") { echo "<form name=\"form1\" method=\"post\" action=\"$SERVER[php_SELF]\"> <table width=\"200\" border=\"0\"> <tr> <td valign=\"top\"><input name=\"title\" type=\"text\" id=\"title\" tabindex=\"1\" value=\"Event Title\" size=\"80\" maxlength=\"100\"></td> </tr> <tr> <td height=\"27\" valign=\"top\"> <input name=\"dd\" type=\"text\" id=\"dd\" tabindex=\"2\" value=\"dd\" size=\"5\" maxlength=\"2\"> <input name=\"mm\" type=\"text\" id=\"mm\" tabindex=\"2\" value=\"mm\" size=\"5\" maxlength=\"2\"> <input name=\"yyyy\" type=\"text\" id=\"yyyy\" tabindex=\"2\" value=\"yyyy\" size=\"10\" maxlength=\"4\"></td> </tr> <tr> <td valign=\"top\"><input name=\"eventTime\" type=\"text\" id=\"eventTime\" tabindex=\"3\" value=\"Time\" maxlength=\"7\"></td> </tr> <tr> <td valign=\"top\"><input name=\"venue\" type=\"text\" id=\"venue\" tabindex=\"4\" value=\"Venue\" size=\"80\" maxlength=\"100\"></td> </tr> <tr> <td valign=\"top\"><textarea name=\"description\" id=\"description\" cols=\"45\" rows=\"5\" tabindex=\"5\">Enter discription here</textarea></td> </tr> <tr> <td valine=\"top\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Add Event\" /></td> </tr> <input name=\"viewed\" type=\"hidden\" id=\"viewed\" value=\"yes\"> </table> </form>"; } else { $title = $_POST[title]; $eventDate = $_POST[dd]."/".$_POST[mm]."/".$_POST[yyyy]; $eventTime = $_POST[eventTime]; $venue = $_POST[venue]; $description = $_POST[description]; echo "<b>".$title."</b><br />".$eventTime." ".$eventDate."<br />".$venue."<br /><br />".$description."<br /><br />This event has been successfully added"; } ?> Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/134439-help-with-a-php-formtwo-quick-questions/#findComment-699917 Share on other sites More sharing options...
Maq Posted November 27, 2008 Share Posted November 27, 2008 Work in progress eh? Instead of all those escaping back slashes you can use single quotes. Anyway for this input field you would do: Quote Link to comment https://forums.phpfreaks.com/topic/134439-help-with-a-php-formtwo-quick-questions/#findComment-699925 Share on other sites More sharing options...
gazfocus Posted November 27, 2008 Author Share Posted November 27, 2008 That's fantastic Thanks again. I really appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/134439-help-with-a-php-formtwo-quick-questions/#findComment-699928 Share on other sites More sharing options...
Maq Posted November 27, 2008 Share Posted November 27, 2008 Let me know how it works out. Quote Link to comment https://forums.phpfreaks.com/topic/134439-help-with-a-php-formtwo-quick-questions/#findComment-699932 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.