1

I am working on a university project in which I have made an admin panel from which I can write/edit "Rules" for university students like

"No student is allowed to have cell-phone in class"

well I have made a <p> element in which 1 rule is written(at the time of designing), I want to change it dynamically using php.

the problem is, I didn't find any method or logic to get text of that p element and then place it in

<textarea> 

so that I can change that rule by editing text in textarea and then update it.

Here is the HTML Code which I am using to add/update a rule.

<form class="form-horizontal">

  <div class="form-group">
    <label for="txt_rule" class="control-label col-sm-3">Rule Description</label>
    <div class="col-sm-6">
      <textarea id="txt_rule" class="form-control" name="txt_rule" rows="3"  value="" placeholder="Add or Update New Rules"></textarea>
    </div>
  </div>
  <div class="form-group">
    <div class=" col-sm-offset-3 col-sm-6">
      <button class="btn btn-info btn-sm" name="addNewRule" value="">Add New Rule</button>
      <button class="btn btn-primary btn-sm" name="update" value="">Update</button>
    </div>
  </div>

</form>

Here is the HTML code which I have designed at time to coding and want to change that p element in it.

<div class="rule col-sm-12">

  <div class="rulenNumber">1</div>
  <p>Rule Description will be written here.</p>

    <a href="#" class="btn btn-danger btn-sm pull-right" >Delete</a>
    <a href="#" class="btn btn-info btn-sm pull-right" >Update</a>

</div>

I want to get text of p element in my textarea using php, so that I can modify it at any time.

https://s21.postimg.org/7xx7rj4yv/Untitled.jpg

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Hassan Raza
  • 376
  • 1
  • 5
  • 15
  • 2
    Now it's time to use some storage and store texts there. – u_mulder Oct 12 '16 at 06:55
  • Kind of like in a file ? – Hassan Raza Oct 12 '16 at 06:56
  • 2
    Or in a database. – u_mulder Oct 12 '16 at 06:56
  • to store in database first i have to get that text from

    element then i can store it .

    – Hassan Raza Oct 12 '16 at 06:57
  • 3
    Or, you could start off with storing it in the database and then load it in the p element and the textarea? Other than that, you'd need to use jQuery, php is server side and can't do anything once the page is loaded in your browser.. – Epodax Oct 12 '16 at 06:59
  • I can't understand your purpose. Do want to get *Rule Description will be written here.* text in `p` using php? – Mohammad Oct 12 '16 at 07:15
  • @Mohammad i think hes purpose will be much bigger than he thinks right now... Take a look at the code, you'll realize there's a ton of work to do to get that working as he wishs... first of all: save the rules. And there the problem starts.. – Twinfriends Oct 12 '16 at 07:20
  • @Mohammad i want to get text of element p in textarea. i want to get "Rule Description will be written here" in textarea. – Hassan Raza Oct 12 '16 at 07:35
  • Does not exist any `p` element in `textarea`. – Mohammad Oct 12 '16 at 07:36
  • @Twinfriends yes i have a lot of work to do like update rule or delete rule etc but i simply want to get-text of p element which is "Rule Description will be written here" in text-area. – Hassan Raza Oct 12 '16 at 07:39
  • http://stackoverflow.com/questions/6399924/getting-nodes-text-in-php-dom – Mohammad Oct 12 '16 at 07:46
  • @Hassan so look, sure we can help you get this text out of the p element and place it in the textarea. But this wouldn't help you. You have to change your complete logic, otherwise you will just run into the next problem. Just listen to Epodax and start with the database part. Trust me, it will me MUCH easier to develop the rest of your application. How well do you know PHP? – Twinfriends Oct 12 '16 at 07:46
  • @Twinfriends i m newbie in php, and it is not a complex project, its so simple nothing to worry about . – Hassan Raza Oct 12 '16 at 07:50
  • @Mohammad i don't have knowledge about DOM – Hassan Raza Oct 12 '16 at 07:51
  • 1
    @Hassan even if it is a simple projekt you will run ito trubbles when you doing it this way, trust me. And thanks for the image, but i understood you since the beginning. Its not that there's no solution for what you want to do, its just that you'll post your next question 5 minutes after you have the answer, because you'll relise that it helps you exactly nothing when you get this text out of this

    element. Imagine, if this rule would be saved in a database, you just can do a simple query and you can place the text of this rule whereever you want! Press update->query->load data, display it

    – Twinfriends Oct 12 '16 at 07:54
  • @Twinfriends Thanks brother , now i got it . Voting up . Good Day . – Hassan Raza Oct 12 '16 at 07:58
  • @Hassan If you need more help or adivses about your next steps, feel free to contact me, i'll try to help you. – Twinfriends Oct 12 '16 at 08:01
  • @Twinfriends Gotcha . – Hassan Raza Oct 12 '16 at 09:38

1 Answers1

1

Its better if we use jQuery here. But if you want to do it PHP you should have DB where all these data is stored. You can do something like this

  1. Every update link should have URL of current page with "id parameter"
  2. For example if your page link is http://example.com/page The anchor tag should have URL like <a href="http://example.com/page?id=1"class="btn btn-info btn-sm pull-right" >Update</a>

  3. And in Textarea you can get it by "$_GET['id']" <textarea> <!--mysql query to get the text from DB based on id--> </textarea>

Patrick R
  • 6,621
  • 1
  • 24
  • 27