11Tami Posted January 4, 2007 Share Posted January 4, 2007 Hi, I already looked all over the web on this and still don't quite understand it.From what I can see $_SERVER['PHP_SELF'] is supposed to keep the same page in the browser when a form sends. If you use it in the form action= area.What I don't understand is usually in a form action you have to connect with what else you need the form to do. Such as sending form fields to something else. A database or an email or something. So if $_SERVER['PHP_SELF']takes up the form action slot, how can you send the form fields? Thanks a lot. Quote Link to comment Share on other sites More sharing options...
fert Posted January 4, 2007 Share Posted January 4, 2007 example[code]<?php if($_POST['text']=="") { echo "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">"; echo "<p><input type=\"text\" name=\"text\"><p><input type=\"submit\" value=\"submit\"></p></form>"; } else { echo $_POST['text']; }?>[/code]like that Quote Link to comment Share on other sites More sharing options...
11Tami Posted January 4, 2007 Author Share Posted January 4, 2007 PERFECT! Thank you very much. I might be back if I get locked up incorporating this in what I'm doing. Quote Link to comment Share on other sites More sharing options...
11Tami Posted January 4, 2007 Author Share Posted January 4, 2007 OK fert, do you know how I could send the form to an email, while its looping it to the same page? For instance. How can I get the same fields to send to an email, while its showing in the echos on the same page. Usual email form.<?php $mailto = 'email@website.com';$sendfield = $_POST['sendfield']; $subject = 'Email subject'; $from = "From: '$sendfield'" . "\n" . $messageproper = 'Field sent to this email: $sendfield\n'; mail('$mailto','subject',$messageproper,$from); ?> Your modified php self code, that keeps the form fields going. How to send to an email at the same time?<?php if($_POST['text']=="") { ?><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><input type="text" name="text"><p><input type="submit" value="submit"></p></form> <?php } else {echo $_POST['text'];?><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><input type="text" name="text"><p><input type="submit" value="submit"></p></form> <?php} ?> Quote Link to comment Share on other sites More sharing options...
fert Posted January 4, 2007 Share Posted January 4, 2007 [code]<?php if($_POST['send_to']=="") { echo "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">"; //insert form fields } else { $headers="From: ".$_POST['from']."<{$_POST['from']}>"; mail($_POST['send_to'],$_POST['subject'],$_POST['msg'],$headers); }?>[/code] Quote Link to comment 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.