How can I POST some values to another page with Wt?

229 Views Asked by At

I have a WAnchor to another page, which changes the internal path. I also have a function internalPathChange() that reacts to internalPathChanged() and that calls the right function depending on the internal path.

How can I use POST to give values from the first page to the second page?

1

There are 1 best solutions below

0
On

You should work with widgets. Wt doesn't known the concept of post and different html pages.

A great example can be found here in the file HangmanGame.C. You create your own widgets, and in the constructor of those widgets you specify which values you need. Then they use a Wt::WStackedWidget for displaying only the new "page".

They use following code:

void HangmanGame::handleInternalPath(const std::string &internalPath)
{
  if (session_.login().loggedIn()) {
    if (internalPath == "/play")
      showGame();
    else if (internalPath == "/highscores")
      showHighScores();
    else
      WApplication::instance()->setInternalPath("/play",  true);
  }
}

void HangmanGame::showHighScores()
{
  if (!scores_)
    scores_ = new HighScoresWidget(&session_, mainStack_);

  mainStack_->setCurrentWidget(scores_);
  scores_->update();

  backToGameAnchor_->removeStyleClass("selected-link");
  scoresAnchor_->addStyleClass("selected-link");
}

void HangmanGame::showGame()
{
  if (!game_) {
    game_ = new HangmanWidget(session_.userName(), mainStack_);
    game_->scoreUpdated().connect(&session_, &Session::addToScore);
  }

  mainStack_->setCurrentWidget(game_);

  backToGameAnchor_->addStyleClass("selected-link");
  scoresAnchor_->removeStyleClass("selected-link");
}

So in this example the HighScoresWidget and HangmanWidget are the "pages" to which you want to post values.