Forum Moderators: coopster

Message Too Old, No Replies

PHP and Buttons in HTML

         

mag1

2:17 pm on Jan 18, 2005 (gmt 0)

10+ Year Member



Hi, I've got a form with a number of input fields on it. I have a javascript function that checks the fields on the click of a submit button. I've also create a hidden input field name=DBConnect this value is set to false on entering the javascript function and to True providing all is OK. Please see below code that I was hoping would work but isn't, any suggestions as to how I should go about doing this? Is it possible?

<button onClick='CheckFields()'
<?php if($DBConnect=="false")
{?> type=button name="Check"<?php}
else if($DBConnect=="True"){?>type=submit name="submit"<?php}?>> Enter Complaint</button>

Thanks

coopster

1:08 pm on Jan 19, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, mag1.

PHP processing happens at the server-side, not on the client. PHP can write out your code for you, but all PHP processing happens at the server. Maybe if you explain a bit more of what you are trying to accomplish, we can help you overcome the issue.

mag1

3:08 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



Hi,

What I'm trying to do is, based on the result of the CheckFields function i.e. Value of DBConnect, I want to determine the type of button. If DBConnect = false then I want the button type to be button, if it's true I want the button type to be submit. I'd like to do some Client side checking of fields before going to the server side.

Does this expain it any better?

Thanks.

coopster

1:02 pm on Jan 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



OK, I think I follow. Have you checked out the JavaScript Jumpstart -- Form Validation threads in the Javascript Library [webmasterworld.com]? I think they explain how to do what you are looking for.

mcibor

10:29 pm on Jan 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To do on client checking use javascript, not PHP

in the html:

<form name="test" id="test" action="index.html" method="POST"><button onclick="java_check(); return false;">Submit</button></form>

in javascript

function java_check()
{
//here you check everything, if fine

document.test.submit();
}

Hope it helps you somehow!
Best regards
Michal Cibor