View Full Version : changing command button to text link?

08-20-2006, 11:50 PM
i'm trying to format a little code i found on hot scripts and have run into a problem trying to replace the submit button with a text link that will do the same thing. here's the code.

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?do=add">
Email Address: <input type="text" name="email"><br>
<input type="submit" value="Submit">

i just think that links look better than buttons.

any help would be greatly appreciated.


08-21-2006, 12:00 AM
<a href="#" onclick="document.form1.submit();">Submit</a>

You'll need to name your form.

08-21-2006, 01:41 AM
thanks for the line but could you give me a clue as to how i name the form?

<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post" >

i remember when i did this with my paypal buttons i had to rename everything to get it to work but with this i'm lost.


08-21-2006, 02:16 AM
<form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?do=add">

Just add name="form1"


08-21-2006, 02:38 AM
i must have some other problems the script's not working.

thanks for your help.

08-21-2006, 03:01 AM
What exactly is going wrong ?

Did it work before you changed things ?

If so, Lets have a look at the original script (before you changed the link to text rather than button) to see if we can spot anything.


08-21-2006, 06:35 AM
okay i got the script working and everything looks good but i'm back to the button thing. i'm sorry to be beating a dead horse here but this is the code i'm working with now. i need to mention that the original code i submitted was an error on my part, sorry.

okay here it is:

<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post">
Your Email: <input type="text" name="email"><br><br>
<input type="submit" name="submit" value="Submit">
<input type="hidden" name="sent" value="yes">

so i add this:

<a href="#" onclick="document.form1.submit();">Submit</a>

and then name the form like this:

<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post" name="form1">

and i get nothing. it just refreshes the screen.

what do you think, and thanks again for all the help

08-21-2006, 11:37 AM
There has to be more code to it surely ?
Otherwise refreshing the screen is all it will do !
Is there no more php and/or javascript near the start of the page ?


08-21-2006, 02:32 PM
i've looked at the entire app but i can't find where the rest is. if you care to take a look here's the link. www.theangrypoet.com/email/

i can only think of two places it would be, the config file and the index file but as i have said before i'm not good at this at all.


08-21-2006, 04:52 PM
First and foremost, you need to validate your html. You have four <html> tags, three </html> tags, mismatched <p>, <span>, and <center> tags, and a number of other simple problems that need to be fixed.

With regards to your submit link, it will do the same thing a submit button will do, but you must make sure in your PHP code you are not referencing $_POST['submit'] anymore, as that form control is no longer there. Without seeing your PHP code (you may want to post it), that's what I suspect is happening.

08-21-2006, 04:53 PM
Well I can look at the page you link to but it will not display any php if I view the source.
Your form action is set to the same page that the form is on. Which is only any good if the page has some php on it, Which it must have because it seems to work. I submit an email and it says it has been submitted. What is it that is not working ?

Post the entire code of the page up here (enclose it in php quotes to make it easy to see what is going on, see just below the attachnents drop down in the reply window)
And lets also have a look at the config page (change any sensitive areas such as passwords or database connection details before posting)


08-22-2006, 01:52 AM
call it an ocd thing but i really don't like buttons, in fact i hate them. when i first saw this app on hot scripts and started to play around with it i really liked it because i could make it look just like my site, which if you can tell from my coding skills is more important to me than say, function.

that said all i would like to do is replace the button that says submit on the page with a text link. trust me crowds, the only script on the file "form.inc" is what i have posted. all the other script is scatered throughout the folder that the app is contained in on the site/server.

if you like i can make a zip file link on my site with the entire app that you can download.

and, sorry for all the trouble. i really appreciate all the attention all of you have given my little problem

file name: index.php

require "config.php";
include "header.inc";
if (isset($sent)) {
if (!$rfields == "") {
$rfields = explode(",", $rfields);
for($i = 0; $i < count($rfields); $i++) {
if ($$rfields[$i] == "") {
echo "You have not completed the required field <b>$rfields[$i]</b>. Please click <a href=\"javascript:history.back(1)\">here</a> to go back and complete the required field. Thank You.";
if (!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)) {
echo "Your email address, $email, does not seem to be valid. Please click <a href=\"javascript:history.back(1)\">here</a> to fill in a proper email address. Thank You.";
$fmail = "The below named has requested to be registered to your mailing list. The following contains the information that was submitted via the online form.\n\n";
$fmail.= "IP Address: $REMOTE_ADDR\n";
$fields = array_keys($HTTP_POST_VARS);
for($i = 0; $i < count($fields); $i++) {
$temp = $fields[$i];
if ($temp == "rfields" || $temp == "submit" || $temp == "sent" || $temp == "y_name" || $temp == "y_email" || $temp == "autor" || $temp == "autor_message" || $temp == "$autor_mail" || $temp == "$autor_subject" || $temp == "after")
$fmail = $fmail;
else {
$temp1 = stripslashes($HTTP_POST_VARS[$temp]);
$fmail.= "$temp: $temp1\n"; }}
$fmail.= "\nSent From (http://www..com)";
$mailed = mail($y_email, "Subscription Registered", $fmail, "From: $name <$email>");
if ($autor == "yes") {
$autor_subject = stripslashes($autor_subject);
$autor_mail = stripslashes($autor_mail);
mail($email, $autor_subject, $autor_mail, "From: $y_name <$y_email>"); }
if(!$mailed) {
echo "There was an error. Please contact <a href=\"mailto:$y_email\">the Webmaster</a>?"; }
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=./write.php?email=$email\">";
} else { ?> <BR>
<? echo "$body_text"; ?><BR>

<? include "form.inc";}
include "footer.inc";

file name:config.php


// Enter the relative path to the re-direct page. A thank you
// Page is included in the script.
$after = "./thankyou.php";

// This is the page title that you would like to appear when a
// user subscrbes to the list.
$page_title = "subscription page";

// Name of the e-mail list. Best to leave this one alone.
$writefile = "email";

// Name of file to write your e-mail list to, the file should be
// writable by your server. Best to leave as-is.
$outfile = "emails.txt";

// Leave this vairable as-is for best results. It format's each line
// So that the script can read your e-mail list.
$writestring = "$email\n";

// I really don't remember what this is or why I put it in here, but
// I am sure there was a good reason for it so just leave it here.
$y_name = "Subscription";

// Again, I beleive I was asleep when I put this in, just leave it alone.
$rfields = "email";

// Your name and e-mail address go here, (e-mail address in the sincle quotes
// and brackets and name in quoted area.
$from_mail = " <'steve@.com'>";

// Your e-mail address goes here for the subscription notification.
$y_email = "steve@.com";

// Set to "yes" to turn on the autorespond, off the decline.
// autorespond will send the subscriber an e-mail notice that
// they have been added to your list.
$autor = "yes";

// Subject of the autorespond e-mail goes here.
$autor_subject = "Thank You, Newsletter";

// This is the welcome message that the user sees when they go to your
// signup page.
$welcome_msg = "Thank you for chosing to register for our newsletter.";

// This is the page test below the welcome message.
$body_text = "Please fill out the form below to begin receiving our newsletter. <BR> <b> Be sure to enter your correct e-mail address in the complete format like: \"me@mydomain.com\". ";

// This is the body of the autorespond e-mail that is sent to the user.
$autor_mail = "Either you or someone else has requested registration in our free newsletter. This email is being sent to you because you or someone else requested it. IT IS NOT SPAM. If you did not request this information, please unsubscribe at: http://www..com.";


file name: form.inc

<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post">
Your Email: <input type="text" name="email"><br><br>
<input type="submit" name="submit" value="Submit">
<input type="hidden" name="sent" value="yes">

file name: write.php



// Open file for APPENDING! NO DATA LOST!!!
if(!$fd = fopen($outfile, "a")) {
echo("Error opening file.");

// Write the string to the file.
if(!fwrite($fd, $writestring)) {
echo("Error writing to file.");



there are six other files in this app and from what i can tell they have noting to so with my problem.

they are:


thanks again:thumbsup:

btw crowds, can't you access a pages code buy writing the url into your editor? i do it all the time with html kit.

08-22-2006, 02:09 AM
header.inc and footer.inc are brought into your index.php. Based on what's in those two files could directly relate to your problem.

PHP code can't be read just by going to that url; the PHP interpreter, well, interprets the code and produces output to the browser. There's no way to see the code that produced the output without the source file.

08-22-2006, 02:35 AM
file name: header.inc

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo "$page_title"; ?></title>

<body link="#66CCCC" vlink="#66CCCC" alink="#66CCCC">
<font face=verdana,arial>
<STYLE type="text/css">
BODY {scrollbar-3dlight-color:#dedf9f;
<a href="http://www.mykazaam.com"><img src="logo.gif" border="0"></a><br>
<table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline">
<td class="catHead" height="25"><span class="genmed"><b><? echo "$page_title"; ?></b></span></td>
<td class="row1" align="left"><span class="gensmall" style="line-height:150%">
<? echo "$welcome_msg"; ?>


file name: footer.inc

<td class="row3" align="left" height="24"><span class="gensmall"><b><a href="http://www.mykazaam.com">www.mykazaam.com</a></b>



08-22-2006, 06:03 AM
I can't see anywhere that $_POST['submit'] is being referred to explicitly apart from that loop that adds all the $_POST variables to $fmail, which shouldn't be a problem if there's no $_POST['submit'].

In any event, you can always add a hidden input field to your form and name it submit with a value of submit; that should adequately simulate the submit button.