/    Sign up×
Community /Pin to ProfileBookmark

Need a form with different buttons.

I’ve got a form I’ve written in PHP.
I’ve got one submit button that changes text that’s inputted into a textfield.

What I need is to have a few more buttons.
When the other buttons are clicked, the textfiels will get formatted ina slightly different way.

I’m scratching ym head since I can’t figure out how I could have more than one button attach to a form.

Stupid question: is this a Javascript or other client side language problem as opposed to a PHP one?
I can’t make my mind up. ?

The code I have so far is:

[code=php]<html><title></title>
<link href=”myCSS.css” rel=”stylesheet” type=”text/css”>
<body>
<?php
IF (isset($_POST[“address”]))
{
$addressString = strtolower($_POST[“address”]);

if(get_magic_quotes_gpc())
{
$addressString = stripslashes($addressString);
}

$addressString = str_replace(“n”, “,”, $addressString);
$myArray = explode(“,”, $addressString);

$numberOfArrayItems = count($myArray);

$myArray[$numberOfArrayItems – 1] = strtoupper($myArray[$numberOfArrayItems – 1]);

$newCorrectFormatAddress = “”;

for ($i=0; $i<=$numberOfArrayItems; $i++)
{
$myArray[$i] = ucwords($myArray[$i]);
$myArray[$i] = trim($myArray[$i]);
$newCorrectFormatAddress = $newCorrectFormatAddress . $myArray[$i] . “n”;
}

$newCorrectFormatAddress = trim($newCorrectFormatAddress);

$onfocus = “”;
}
ELSE
{
$newCorrectFormatAddress = “Please enter your address”;
$onfocus = “onfocus=’form.address.value=””‘”;
}
?>

<br>
<form action=”index.php” method=”post” name=”addressFixer”>

<textarea name=”address” cols=”40″ rows=”6″ class=”blueText” <?php print $onfocus; ?>><?php echo $newCorrectFormatAddress; ?></textarea>

<br>
<br>

<label>
<input type=”submit” name=”Submit” value=”Submit”>
</label>
</form>
</html>[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Jan 16.2007 — It's both.

HTML/PHP to add additional buttons and Javascript to change the appearance of existing fields.
Copy linkTweet thisAlerts:
@OM2authorJan 16.2007 — thanks for the reply.

appearence isn't really what i need.

may you misunderstand.

let me explain by giving an example.

let's say you have 3 buttons.

  • - button 1 formats the text and does nothing else.

  • - button 2 formats the text and makes the last line all capitals.

  • - button 3 formats the text and makes the second last line all capitals.


  • i can't think how you could have one form and make it change one textarea.

    hmm... just had a thought...

    could one solution be to have 3 forms and have one textarea outside.

    the forms then change the textarea...?

    hmmm... not sure if that means playing around with javascript and css??
    Copy linkTweet thisAlerts:
    @NightShift58Jan 17.2007 — let me explain by giving an example. let's say you have 3 buttons.

    - button 1 formats the text and does nothing else.

    - button 2 formats the text and makes the last line all capitals.

    - button 3 formats the text and makes the second last line all capitals.
    [/QUOTE]
    The changes you want to make affect the appearance of the text, including <textarea>. For that, you'll have to use javascript - unless you want to submit the form, reload the page and let PHP do the formatting for you - which means a potential reload for Button 1, another one for Button 2 and again for Button 3. With javascript, you could do that "in situ" before submitting the form.
    Copy linkTweet thisAlerts:
    @OM2authorJan 17.2007 — thanks for the reply.

    hmmm a little confused.

    what's "in situ"?

    can i do this: when one of the buttons are pressed... a specific variable gets set.

    each button sets a different value to this variable.

    would that be a good idea?

    i just had a thought: the reformatting of the text would be better done in javascript.

    don't really need to involve php at all.

    but... i'm glad i did it... it was second ever php script. ?

    would there be any reason to avoid javascript?

    thanks.
    Copy linkTweet thisAlerts:
    @NightShift58Jan 17.2007 — "in situ" means "in place", as in on the same page, without moving, i.e. reloading.

    There is one reason to avoid javascript - especially if it's critical to the task you are trying to perform. A good number of browsers have Javascript disabled as a security measure.

    This means that it's okay to use Javascript to validate a form submission BUT your PHP code should do the same once again to ensure that incorrect input didn't go through due to the unavailabilty of Javascript.

    The advantage of Javascript is that it enables to be a bit more interactive with your visitors but you cannot rely on it being available and, as mentioned, mission essential tasks need to be checked server-side.
    ×

    Success!

    Help @OM2 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...