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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with forms

Status
Not open for further replies.

daybase

Technical User
Dec 13, 2002
115
GB
Is it possible to put a button on a form which could call a function that would format a text input box before the form is submitted?

For example a standard form with a text input and an icon or button which when clicked formats the text eg uppercase or lowercase before the submit button actually passes the data to a script for processing?
 
Of course, through Javascript ( PHP however is executed on the server and when you are fiddling with the form, PHP has already done its job and there is nothing it will do until next page is requested. Meaning that what you wish cannot be done in PHP. Relying on client-side technology (if it is not controlled environment) is risky and from what you are describing it might be better to format the text in php AFTER the user submits the form. End result should be the same, since you can do anything with the submitted variables on the next page that you would have done through JavaScript on the first.
 
That is what I do now but I would like user to be able to preview the format before submitting it. I also have a form for submitting reports and it would have been good to have buttons to insert standard paragraphs prior to submitting
 
It's your choice. You can either take this to Javascript forum and do it client-side or continue doing it like you are. You could consider adding a page with all the data inserted for the person to review before submitting. That way you could still do it in PHP.
 
Why dont you simply make a Preview button?
Then you use:

Code:
if (isset($submit)) {
    $_POST['name'] = ucfirst(strtolower(strip_tags($_POST['name'])));
  }

and, in your form:
Code:
<input type="text" name="name" value="<?=$_POST['name']?>" />

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top