John
John

Reputation: 4944

Hard-Coding a Form so User Can't Edit It

I would like to hard-code the form below. In other words, I would like to post $submission and $fullurl to index.php as "tweet" without giving the user the option to edit them.

How can I do this?

EDIT: I want the user to still click a button that says "Tweet" to post the variables.

Thanks in advance,

John

<form method='post' action='index.php'>

<br />

<textarea  name="tweet" cols="50" rows="5" id="tweet" ><?php echo $submission ?> <?php echo $fullurl ?></textarea>

<br />

<input type='submit' value='Tweet' name='submit' id='submit' />

</form>

Upvotes: 0

Views: 1678

Answers (4)

Jess
Jess

Reputation: 8700

You could just make it completely invisible (style="visibility:hidden"), or disable it (`disabled="true"').

You can also just use document.getElementById('formID').submit(); to submit the form automatically.

Better yet, just make them all hidden inputs, and submit on page load with the above code.

Upvotes: 1

Jason McCreary
Jason McCreary

Reputation: 73011

  • You could set the disabled attribute of the <textarea>. But then it would not be submitted with the form. So you'd have to make a hidden input with the value or use sessions to persist the data if it could not be recreated therwise.
  • You could also use JavaScript to blur the text area on focus. But there are ways around this, i.e. disable JavaScript.

In the end, I think you should reconsider the user interface and user experience. A textarea that isn't editable, probably should be a form element. Just display the data you plan to tweet and allow them to Appove it.

Upvotes: 1

Cyclone
Cyclone

Reputation: 18295

I'm not entirely sure what you are asking, but it sounds like you just want to have some variables kept serverside without a user being able to edit them, between page loads.

In that case you may wish to learn about Sessions and session variables. These allow you to store stuff in between page loads without a user being able to edit them (but you can still read from them so you can display your variables on the page!)

If you could perhaps rephrase your question some if this isn't the answer you are looking for, we would be better able to assist you.

Upvotes: 1

deceze
deceze

Reputation: 522382

<form method='post' action='index.php'>

<p><?php echo $submission ?> <?php echo $fullurl ?></p>

<input type="hidden" name="tweet" value="<?php echo $submission ?> <?php echo $fullurl ?>">

<input type='submit' value='Tweet' name='submit' id='submit' />

</form>

That still doesn't mean the user won't be able to doctor the value through, everything's editable client-side one way or another. Save the to-be-submitted tweet server-side in a session if you need absolutely immutable values.

Upvotes: 4

Related Questions