Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Submit' a default value 2

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
Hi all

Have a form containing the following:-
Code:
<input name="phoneno" type="text">
It is not a required field and the user is directed, on submit, to a second form which advises the content that has been sent, such as:-
Code:
My phone no is $phoneno
If $phoneno is empty, would like to either 'submit' a default value such as "Not entered" or display a default value in the second form?

TIA

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Hi

You can do it in the document :
JavaScript:
<form action="" onsubmit="if(this.phoneno.value=='')this.phoneno.value='Not entered'">
Or on the server :
PHP:
if ($phoneno=='') $phoneno='Not entered';
I suggest to do it on the server.

Feherke.
 
You must be using some server-side language to receive the input from the first form and display the second one. I suggest you amend the code you're using to display the information how you want.

If you have trouble doing that, ask for help in the appropriate forum (at a guess either forum219 or forum434 )

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
feherke, ChrisHunt

Thanks for your replies.

Yes, Chris, there is a PHP script, formmail, processing the input, but the second webpage is also .html, not .php.

I accept a server side conversion would be better but feherke's first suggestion works as required without needing to 'convert' the second webpage to .php to be able to utilise the php suggestion.

Thanks again

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Huh?

Your original form, on a static HTML page, submits its data somewhere, I'd expect a php script, but who knows?

That "somewhere" code populates a second page using code like this (quoted from your original post):
Code:
My phone no is $phoneno

The second page is thus clearly not a plain HTML page, it's being built dynamically somehow by something. That is the code you need to change to get the behaviour you desire, and the language it uses should indicate the forum in which to get help.

Whatever language it is, it can't be HTML, as HTML doesn't have variables that you can put in where you like (if only!). It might be javascript, it might be that your server is set up to parse .html files for PHP commands. I can't tell, but you should be able to find out.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Hi

Chris said:
The second page is thus clearly not a plain HTML page,
Not necessary. It can be a placeholder replace later with actual value by JavaScript.
Code:
window.onload=function() {
  document.body.innerHTML=document.body.innerHTML.replace(/$honeno/g,getParam('phoneno'));
}
Total nonsense anyway.

"Converting" HTML into PHP is not a big deal.

Feherke.
 
ChrisRChamberlain said:
Yes, Chris, there is a PHP script, formmail, processing the input, but the second webpage is also .html, not .php.
Just to clarify the situation, this is the code from the second page.
Code:
<!-- IE Quirks Mode -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Motor House (Stroud) Ltd</title>
<link rel="stylesheet" href="source/motorhouse.css" type="text/css" />
<link rel="shortcut icon" href="icons/favicon.ico" type="image/x-icon" />
<!-- Leave in head for cross browser compatability -->
<style type="text/css">
@media screen {
body>div#header {
	position:fixed;
}
body>div#left-sidebar {
	position:fixed;
}
}
* html body {
	overflow:hidden;
}
* html div#content {
	height:100%;
	overflow:auto;
}
</style>
</head>
<!-- <body OnLoad="document.f1.t1.focus()">-->
<body>
<div id="header"><span style="position:absolute;top:0px;left:0px;background:#000000;width:95%;"><img src="jpgs/AstonMartinDBS-1.jpg" alt="" height="125" /></span> <span style="position:absolute;top:122px;left:0px;"><img src="jpgs/gradient-1.jpg" alt="" /></span> <span style="position:absolute;top:13px;left:270px;"><img src="pngs/MotorHouse.png" alt="" /></span> <span style="position:absolute;top:50px;left:340px;"><img src="pngs/over40years.png" alt="" /></span> <span style="position:absolute;top:75px;left:415px;"><img src="pngs/oneofthelongest.png" alt="" /></span> <span style="position:absolute;top:100px;left:419px;"><img src="pngs/businessesin.png" alt="" /></span> <span style="position:absolute; left:140px;top:158px"><img src="pngs/thankyouenquiry.png" alt="" /></span> </div>
<div id="left-sidebar"> <br />
  <div class="addressblock"><strong>Dudbridge Road<br />
    Stroud<br />
    Gloucestershire<br />
    GL5 3HF</strong><br />
    <br />
  </div>
  <div class="openinghours">
    <!-- Contact details tag -->
    <span> <b>Tel:</b>&nbsp;01453 751384<br />
    <b>Fax:</b>&nbsp;01453 752217<br />
    <br />
    <span>Mon-Sat 8:30am-5:30pm<br />
    Sun: By Appointment Only</span><br />
    <br />
    </span> <span>Evenings or weekends call</span> </div>
  <div class="map"><img src="jpgs/map.jpg" alt="" height="62" /></div>
  <div class="phonenos"> <span style="font-style:italic;"></span> <b>Mobile:</b>&nbsp;07980 867887<br />
    <br />
    <a href="[URL unfurl="true"]http://www.motrac.co.uk/motorhouse/index.html"[/URL] title="Home page"><b>Home page</b></a><br />
    <a href="[URL unfurl="true"]http://www.motrac.co.uk/motorhouse/googlemap4.html"[/URL] title="View a map of our location"><b>Map: Find us</b></a><br />
    <a href="[URL unfurl="true"]http://www.motrac.co.uk/motorhouse/aboutus.html"[/URL] title="Meet the Motor House team"><b>Enquire: About us</b></a>
  </div>
  <div class="scroller"> <br />
    Customer testimonials...<img src="gifs/testimonials.gif" alt="" /> </div>
</div>
<div id="content">
  <div class="contactus"><br /> Thank you for submitting your enquiry to us and we will respond if a reply is required. <br />
    <br />
    To reduce the risk of spam, we will not be sending you an auto-response email, and
    instead here is the information you submitted:<br /><br />
    You will be redirected to the Home page in four seconds<br />
    <br />
    <b> My name is $realname <br />
    <br />
    My email address is $email <br />
    <br />
    My phone no is $phoneno<br />
    <br />
    My message is $mesg <br />
    <br />
    
  </div>
</div>
<!--end content -->
<script language="javascript" type="text/javascript">
     <!--
     var myDomain = location.protocol + '//' +
                    location.hostname +
                    location.pathname.substring(0, location.pathname.lastIndexOf('/')) +
                    '/index.html';
     window.setTimeout('window.location="' + myDomain + '"; ',4000);
     // -->
</script>
</body>
</html>
The second page appears, unless the form does not validate, immediately after 'submitting' the form.

As you can see, the Javascript at the end of the page only serves to redirect the page.

You can see it working at
FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Your first page has this field in it:
Code:
      <input type="hidden" name="good_template" value="[URL unfurl="true"]http://www.motrac/motorhouse/contactusaccept.html"[/URL] />
That rather implies that formmail.php is using contactusaccept.html as a template with which to produce the second page.

So it should be possible to dig around in formmail.php to get it to behave in the way you want. Whether it's desirable to do such a thing when it's a script you've probably brought in from a third party may be another matter.

If you're happy with the Javascript approach, you might as well stick with it. After all, the worst that can happen is that somebody has JS switched off, and gets a blank "My phone no is" line in their page2.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Whether it's desirable to do such a thing when it's a script you've probably brought in from a third party may be another matter.
The behaviour appears to be acceptable although the coding may be 'untidy' from a professional point of view, but prepared to go with it as is.[smile]


From an educational point of view, am puzzled at to why you and feherke refer to
Code:
<form action="" onsubmit="if(this.phoneno.value=='')this.phoneno.value='Not entered'">
as being Javascript when there's no declaration as such?

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Hi

Chris said:
From an educational point of view, am puzzled at to why you and feherke refer to [gray](...)[/gray] as being Javascript when there's no declaration as such?
That was the information for you, to know what to specify as The default scripting language.
W3C said:
Documents that do not specify default scripting language information and that contain elements that specify an intrinsic event script are incorrect.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top